I have an application that run sound notification from broadcast receiver every specific period and the user can adjust the sound level by selecting the level of notification sound from preference, and after the media file finish running i use a time scheduler to restore back the sound level to the original status after 20 second .
this method is not good enough, and I want any suggestions to restore back the sound level once the media file finished playing, and without disturbing the phone user.
{
localBuilder.setSound(localUri,AudioManager.STREAM_NOTIFICATION);
StringBuilder localStringBuilder2 = new StringBuilder();
localStringBuilder2.append(localSharedPreferences.getString(
"prefSyncsound", "NULL")); int XV =
Integer.parseInt(localStringBuilder2.toString());
final AudioManager localAudioManager = (AudioManager)
paramContext .getSystemService(Context.AUDIO_SERVICE);
final int maxv = localAudioManager
.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION); final int
currentVolume = localAudioManager
.getStreamVolume(AudioManager.STREAM_NOTIFICATION); if
(currentVolume != XV)
{
if (localAudioManager
.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
Toast.makeText(paramContext, "sound is off",
Toast.LENGTH_LONG).show(); } else {
int volt = (int) Math.round(((double) XV / 100) * maxv);
localAudioManager.setStreamVolume(
AudioManager.STREAM_NOTIFICATION, volt,
AudioManager.ADJUST_SAME);
Timer mTimer = new Timer(); mTimer.schedule(new TimerTask() { //
@Override public void run() {
localAudioManager.setStreamVolume(
AudioManager.STREAM_NOTIFICATION, currentVolume,
AudioManager.ADJUST_SAME);
} }, 20000);
}
}
}
localNotificationManager.notify(0, localBuilder.build());
wl.release();
return;
2nd question.
also I want to stop the notification sound from firing in case the user is playing media file or using any media sound, this is not to disturb the user.