title: How to change audio mode programmatically only when notification is happening in android?
body: <p>I want to ask how to change audio mode temporarily only when notification is happening?</p>
  
  <p>For instance, I want my current mode is silent, no sound and no vibration. When notification is happening sound volume is max and with vibration. After notification is done, I want to change it back to silent mode without sound and vibration.</p>
  
  <p>The problem is, I can change from silent to max volume and with vibration, but the audio settings still max sound with vibration after the notification is done.</p>
  
  <p>This is my code:</p>
  
  <pre><code>AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  
  audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,
                               audioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION),
                               AudioManager.FLAG_ALLOW_RINGER_MODES);
  
  NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  notificationManager.notify(GCMHandler.MESSAGE_NOTIFICATION_ID,
                             NotificationBuilder.build(context,
                                                       "Mohon konfirmasi booking #" + bookings.last().getCode(),
                                                       "Booking #"+bookings.last().getCode()+" belum dikonfirmasi!",
                                                       NotificationBuilder.Type.PUSH_NOTIFICATION,
                                                       R.drawable.notif_icon, 0xFFC200));
  </code></pre>
  
  <p>and if I put <code>audioManager.setRingerMode(RINGER_MODE_SILENT)</code> after <code>notificationManager.notify()</code>, the notification just built with full silent mode </p>
  
  <p>Regards,</p>