I have an application that creates a notification with sound when a specific text comes in. To do this, I detect the current ringerMode, change the ringerMode to normal, play the sound, and then quickly return the ringer back to its original setting. Here is the code:
public static AudioManager audio;
audio = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
ringMode = audio.getRingerMode();
if (ringMode < 2)
//Checks to see if the phones ringer is set to silent, or vibrate
audio.setRingerMode(2);
//vibrates phone in a pattern
long[] pattern = {0, 25};
//long[] pattern = {0, 1000, 100, 100, 100, 100, 100, 1000};
v.vibrate(pattern, -1);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
//delays return back to original volume so notification can be heard
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
audio.setRingerMode(ringMode);
}
}, 4000);
}
This works completely fine in an activity, but not in this notification service, and is currently placed in the onStart method. uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" has also been added to the manifest. Any ideas? Thanks