我有一个应用程序,可以在每个特定时间段内从广播接收器运行声音通知,用户可以通过从首选项中选择通知声音级别来调整声级,并在媒体文件完成运行后使用时间调度程序恢复20秒后声级达到原始状态。
这种方法不够好,我希望在媒体文件播放结束后恢复声级,并且不会打扰手机用户。
{
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;
第二个问题。
我也希望在用户正在播放媒体文件或使用任何媒体声音时停止发出通知声音,这不是为了打扰用户。