android 取消多个闹钟,如何在android中取消闹钟

我只是编辑我以前的问题(android模式锁) . 谢谢你的帮助..现在我想知道如何取消闹钟 .

protected void setReminder(Date reminder_date){// TODO自动生成的方法存根

String al_date = sdf.format(reminder_date);

Log.d("alarm_date", al_date);

int r_day, r_month, r_year;

Calendar ca = Calendar.getInstance();

ca.setTime(reminder_date);

r_day = ca.get(Calendar.DAY_OF_MONTH);

r_month = ca.get(Calendar.MONTH);

r_year = ca.get(Calendar.YEAR);

Log.d("new month", String.valueOf(r_month));

Calendar calendar = Calendar.getInstance(TimeZone.getDefault(),

Locale.getDefault());

calendar.set(Calendar.MONTH, r_month);

calendar.set(Calendar.YEAR, r_year);

calendar.set(Calendar.DAY_OF_MONTH, r_day);

calendar.set(Calendar.HOUR_OF_DAY, 10); // HOUR

calendar.set(Calendar.MINUTE, 15); // MIN

calendar.set(Calendar.SECOND, 0); // SEC

calendar.set(Calendar.AM_PM, Calendar.AM);

Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);

pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0,

myIntent, 0);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

int level=getAPILevel();

if(level == android.os.Build.VERSION_CODES.KITKAT) {

alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),

pendingIntent);

}

if(level < android.os.Build.VERSION_CODES.KITKAT) {

alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),

pendingIntent);

}

Log.d("alarm","on");

}

这就是我设置闹钟的方式 . 这工作正常......但问题是即使过期时也会发送通知 .

这是我的接收器课程 . 公共类MyReceiver扩展BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent)

{

Intent service1 = new Intent(context, MyAlarmService.class);

context.startService(service1);

}

}

MyAlarmService.class

@SuppressWarnings({“static-access”,“deprecation”})@Override public void onStart(Intent intent,int startId){super.onStart(intent,startId);

mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);

Intent intent1 = new Intent(this.getApplicationContext(),HomePage.class);

Notification notification = new Notification(R.drawable.ic_launcher,"Time for payment!", System.currentTimeMillis());

intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(),0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);

notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.setLatestEventInfo(this.getApplicationContext(), "Finance Manager", "Time for payment!", pendingNotificationIntent);

Log.d("Notification","send");

mManager.notify(0, notification);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值