我有一个Android应用程序。当应用程序运行时,应该将警报静音或禁用。关闭应用程序后,应重新启用告警。我使用了以下代码:
AudioManager AudiMngr = (AudioManager) getSystemService(AUDIO_SERVICE);
AudiMngr.setRingerMode(AudioManager.RINGER_MODE_SILENT);
AudiMngr.setStreamVolume(AudioManager.STREAM_ALARM, 0, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);
Toast toast = Toast.makeText(getApplicationContext(), "Sound Muted", Toast.LENGTH_SHORT);
toast.show();但它只在应用程序启动时起作用。当告警达到告警时间时,启用告警。我希望将警报静音,直到应用程序关闭。我该怎么做呢?
发布于 2014-05-26 19:04:01
要禁用警报,请执行以下操作
AlarmManager aManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(getBaseContext(), YourAlarmSetClass.class);
PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
aManager.cancel(pIntent);发布于 2014-05-26 18:54:58
调用方法cancel(...)在AlarmManager中,使用您用于设置警报的同一个PendingIntent。示例:
mAlarmPendingIntent = PendingIntent.getActivity(this, requestCode, intent, flags);
this.getAlarmManager().cancel(mAlarmPendingIntent);这指的是您要取消报警的活动或服务。
https://stackoverflow.com/questions/23868439
复制相似问题