title: Ringtone mode changed during incoming call in Android. Need for Text to speech app
body: <p>During incoming call user can put the ringing of the phone in silent but pressing the volume up down or power on button in Android Phones. I am creating a speak caller name app where in my app will speak the name of the caller. I am not muting the current ringtone. Everything is working fine in  my app except when phone is ringing during incoming call and user put it on silent by pressing the volume or power button. I am unable to handle this trigger. I tried AudioManager and RingToneManager class but in vain.
  My app has one activity (App settings), One BroadCast reciever class(for capturing incoming call) and one service(to trigger TTS engine).</p>
  
  <p>Code :</p>
  
  <pre><code>    private void SpeakCallerName(String txtSpeak) {
  
      Runnable runnable = new Runnable() {
  
          @Override
          public void run() {
              Ringtone ringtone = null;
              _status = "SpeakService speak Runnable phoneRinging: " + phoneRinging;
  
               Log.i("Test", _status);
               int i =0;
  
  
              try {
              while(phoneRinging) {
                  AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                   _status = "SpeakService speak Runnable inside while loop count: "+i + "phoneRinging:" + phoneRinging;                   
                   Log.i("Test", _status);
                   int Mode = audioManager.getMode();
  
                   _status = "SpeakService speak Runnable inside while loop count: "+i + ":audioManager.getMode():" + Mode;                    
                   Log.i("Test", _status);
  
                   int ringerMode=audioManager.getRingerMode();
                   _status = "SpeakService speak Runnable inside while loop count: "+i + ":audioManager.getRingerMode():" + ringerMode;                    
                   Log.i("Test", _status);
  
                   int StreamVolume=audioManager.getStreamVolume(AudioManager.STREAM_RING);
                   _status = "SpeakService speak Runnable inside while loop count: "+i + ":audioManager.getStreamVolume:" + StreamVolume;                  
                   Log.i("Test", _status);
  
  
  
  
              myTts.speak(_txtSpeak,TextToSpeech.QUEUE_FLUSH,null);
  
  
                  Thread.sleep(5000);
  
                  _status = "SpeakService speak Runnable count: "+i + " slept for 8 sec";
  
                   Log.i("Test", _status);
                   i+=1; 
              }
              }
              catch (InterruptedException e) {
  
                  e.printStackTrace();
              }
              catch (Exception e) {
  
                  _status = "SpeakService speak Runnable count: "+i + " EXCEPTION: " + e.getMessage();
  
                   Log.i("Test", _status);
              }
  
  
  
          }
  
       };
  
       Thread mythread = new Thread(runnable);
          mythread.start();
  }
  </code></pre>
  
  <p>My log is like this:</p>
  
  <p>SpeakService speak Runnable inside while loop count: 1phoneRinging:true
  SpeakService speak Runnable inside while loop count: 1:audioManager.getMode():1
  SpeakService speak Runnable inside while loop count: 1:audioManager.getRingerMode():2
  SpeakService speak Runnable inside while loop count: 1:audioManager.getStreamVolume:7</p>
  
  <p>When the user presses the volume or power button i still get the above values in the log.</p>