我只是编辑我以前的问题(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);

}

android 取消多个闹钟,如何在android中取消闹钟相关推荐

  1. chatgpt赋能python:如何在Python中取消换行?

    如何在Python中取消换行? 如果你是一名经验丰富的Python工程师,你一定会遇到在输出过程中需要取消换行的情况.在本文中,我将告诉你如何使用Python取消换行. 什么是换行? 在计算机编程中, ...

  2. android指定日期闹钟,如何在android中设置特定日期的闹钟?

    嗨我需要使用时间选择器来设置特定日期的闹钟.当我给出静态输入时,闹钟设置不正确并响铃. 例如:我给静态输入(与日期,月份和年份),但它不振铃.这是我的代码.如何在android中设置特定日期的闹钟? ...

  3. android 文本后图标_如何在Android中更改文本,图标等的大小

    android 文本后图标 Let's face it: no matter how good the screens are on our phones and tablets, the text ...

  4. android studio点击图片,如何在Android Studio中的模拟器图库中添加图像?

    如何在Android Studio中的模拟器图库中添加图像? 我正在开发图像过滤器应用程序. 但是,如果我没有任何图像,就无法真正尝试. 我知道我可以在电话中对其进行测试,但这并不相同,因为我需要错误 ...

  5. android开发使用c+_如何在Android项目中开始使用C ++代码

    android开发使用c+ by Onur Tuna 通过Onur Tuna 如何在Android项目中开始使用C ++代码 (How to start using C++ code in your ...

  6. android 调出键盘表情_如何在Android的G板键盘中搜索表情符号和GIF | MOS86

    老实说,这里是1010mh1112 GIF和表情符号是新形式的沟通.像他们似乎愚蠢的,他们以某种方式添加了一个额外的层次,我们与朋友和家人通过文本或即时消息交互的方式,否则可能会干燥.虽然表情符号长期 ...

  7. android开发 转跳功能,如何在Android中利用Intent实现一个页面跳转功能

    如何在Android中利用Intent实现一个页面跳转功能 发布时间:2021-02-20 17:06:31 来源:亿速云 阅读:113 作者:Leah 本篇文章为大家展示了如何在Android中利用 ...

  8. android 设置文本加粗,如何在Android中将文本更改为粗体?

    如何在Android中将文本更改为粗体? 如何更改Android TextView中的文本/字体设置? 例如,如何使文本变粗? 15个解决方案 482 votes 要在Typeface文件中执行此操作 ...

  9. android 泰文ttf字体,如何在Android上正确显示泰语diactirics?

    简短的序言.泰语字母有可能出现在辅音上方的元音符号,并且在辅音上方也存在变音符号(DS).当元音和DS出现时,它们出现一个在另一个之上,所以元音被设置在辅音之上并且DS被设置在元音之上.如何在Andr ...

  10. android 工具栏沉浸 下拉,如何在Android应用中实现一个沉浸式状态栏效果

    如何在Android应用中实现一个沉浸式状态栏效果 发布时间:2020-12-08 17:04:42 来源:亿速云 阅读:151 作者:Leah 这篇文章将为大家详细讲解有关如何在Android应用中 ...

最新文章

  1. 【Android】Touch事件分发
  2. 读阿里亿级日活网关通道架构演进有感
  3. C#7.0之ref locals and returns (局部变量和引用返回)
  4. (第2部分,共3部分):有关性能调优,Java中的JVM,GC,Mechanical Sympathy等的文章和视频的摘要...
  5. python中字典的键是唯一的吗_在python3中反转字典中的键和值(值不唯一)
  6. 轻松带你走进shiro的世界
  7. 王道机试指南读后总结-4(有迷宫问题)
  8. linux dhcp rpm 安装
  9. Linux 学习笔记 二
  10. 遍历系统进程和对应模块以及创建进程
  11. redis需要掌握的知识点
  12. 流媒体技术学习笔记之(十六)H264编码profile level控制
  13. 用最简单的例子告诉你kafka是怎么用的
  14. 怎么用屏幕录像工具录制游戏的精彩时刻
  15. Python pandas库的简单使用
  16. 此网站的安全证书有问题
  17. X书app数美-sid分析
  18. 计算机网络协议指的是tcp ip协议吗,计算机除了有网络协议也就是TCP/IP协议以外,还有什么协议呢?...
  19. kermit开发板启动Linux乱码,Ubuntu下C-kermit的使用
  20. 什么是响应式编程,Java 如何实现

热门文章

  1. 二分图最大权匹配:Kuhn-Munkres算法
  2. MYSQL正在使用select发现现场记录方法,包括一个逗号分隔的字符串
  3. Redis系列(二)-Hredis客户端设计及开源
  4. UML依赖,关联,组合,聚合,继承,实现的关系
  5. 为什么会有Memlink? redis
  6. 2 网段 Vlan+NAT 配置
  7. java B2B2C 多租户电子商城系统-SpringCloud动态刷新配置信息
  8. Python 有那么神吗?
  9. shell脚本显示颜色的设置
  10. MySQL5.7 服务 crash 后无法启动