1
私が取り組んでいるアプリケーションにアラームを追加しようとしていますが、何らかの愚かな理由のためにアラームが鳴っても、アプリ。アラームはアプリケーションを殺さずに鳴るのを止めることはありません
アラームはToggleButtonによってアクティブになります。それがオンになっていると、予定された時刻にアラームが鳴り、オフになっても、それは...または少なくとも想定されません。
ここではトグルボタンのonclickコードです:私は解決策であるため作ってみた
public void onReceive(Context context, Intent intent) {
//this will update the UI with message
RemindersActivity inst = RemindersActivity.instance();
//Sets the content of AlarmText in RemindersFragment
inst.setAlarmText("Alarm! Wake up! Wake up!");
//this will sound the alarm tone
//this will sound the alarm once, if you wish to
//raise alarm in loop continuously then use MediaPlayer and setLooping(true)
Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if (alarmUri == null) {
alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);
ringtone.play();
ComponentName comp = new ComponentName(context.getPackageName(),
AlarmService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}