Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Register for <code>AUDIO_SERVICE</code> and then use the <code>AudioManager</code> to control the volume up/down or set profiles.</p> <p>Or if you want to listen for changes in the Audio focus then make your Activity <code>implements AudioManager.OnAudioFocusChangeListener</code>. Override unimplemented method. Create switch that will take care of types of changes.</p> <p>Like:</p> <pre><code>@Override public void onAudioFocusChange(int focusChange) { switch(focusChange) { case AudioManager.AUDIOFOCUS_GAIN: //do something break; case AudioManager.AUDIOFOCUS_LOSS: break; } </code></pre> <p>Or if you want to listen for changes on the audio output, like unplugging the headphones (switching to phone speaker) use <code>ACTION_AUDIO_BECOMING_NOISY</code> sticky broadcast</p> <p><a href="http://developer.android.com/reference/android/media/AudioManager.html#ACTION_AUDIO_BECOMING_NOISY" rel="nofollow">http://developer.android.com/reference/android/media/AudioManager.html#ACTION_AUDIO_BECOMING_NOISY</a></p> <p><a href="http://developer.android.com/reference/android/media/AudioManager.html#RINGER_MODE_SILENT" rel="nofollow">http://developer.android.com/reference/android/media/AudioManager.html#RINGER_MODE_SILENT</a></p> <p>See here</p> <p><strong>Edit</strong>: This is the solution. There was no need to handle AudioFocus but just set different ringer profile or adjusting volume</p> <pre><code>if (hour == myTime.getHour() &amp;&amp; minute == myTime.getMinute()) { if (Settings.getSetMyTime(this)) showNotificationAlarm(R.drawable.icon, "It's time to work"); AudioManager audiomanager =(AudioManager)YourActivityName.this.getSystemService(Context.AUDIO_SERVICE); audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT); //or adjust volume here instead setting silent profile for the ringer } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload