我安排来自活动的闹钟,如。
private AlarmManager mAlarmManager;
mAlarmManager = (AlarmManager) ACT_ActiveSession.getAppContext()
.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(mContext, LocalNotification.class);
intent.putExtra("alertBody", "");
intent.putExtra(K.SESSIONID, "");
intent.putExtra("TIME", "");
intent.putExtra("BATCHNO","");
intent.putExtra("REQUEST_CODE", "");
PendingIntent pendingIntent = PendingIntent.getBroadcast(
ACT_ActiveSession.getAppContext(), REQUEST_CODE, intent, 0);
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, finishTime,
pendingIntent);
// alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, finishTime,
// (1 * 1000), pendingIntent);
intent.putExtra("","");
仅用于BroadcastReceiver
从片段中取消警报
private AlarmManager mAlarmManager;
mAlarmManager = (AlarmManager) mActivity
.getSystemService(Context.ALARM_SERVICE);
Intent updateServiceIntent = new Intent(mActivity,
ACT_Home.class);
PendingIntent pendingUpdateIntent = PendingIntent.getBroadcast(
mActivity, REQUEST_CODE,
updateServiceIntent, 0);
pendingUpdateIntent.cancel();
// Cancel alarms
if (pendingUpdateIntent != null) {
mAlarmManager.cancel(pendingUpdateIntent);
Log.e("", "alaram canceled ");
} else {
Log.e("", "pendingUpdateIntent is null");
}
但警报管理器未被取消。
在这里,我更改mActivity
= MyActivity
'静态getApplicationContext();
,并更改不同的标志和不同的上下文。
答案 0 :(得分:1)
您可以使用此Intent
:
Intent intent = new Intent(mContext, LocalNotification.class);
但您尝试使用此Intent
取消它:
Intent updateServiceIntent = new Intent(mActivity, ACT_Home.class);
这些Intent
不匹配,因此取消不执行任何操作。如果您要取消闹钟,则需要在取消呼叫中使用Intent
,该呼叫与您用于安排闹钟的Intent
匹配。