最近在看Android app 的时候,发现闹钟app 还是挺有趣的,于是写了一个练手。下面上图片

发现最新的Android系统已经不能使用旧版的通知 了,否则,闹铃不会响。所以修改了源码,支持android 10 。下面展示主要代码

 if (Alarms.ALARM_KILLED.equals(intent.getAction())) {// The alarm has been killed, update the notificationupdateNotification(context, (Alarm)intent.getParcelableExtra(Alarms.ALARM_INTENT_EXTRA),intent.getIntExtra(Alarms.ALARM_KILLED_TIMEOUT, -1));return;} else if (Alarms.CANCEL_SNOOZE.equals(intent.getAction())) {Alarms.saveSnoozeAlert(context, -1, -1);return;} else if (!Alarms.ALARM_ALERT_ACTION.equals(intent.getAction())) {// Unknown intent, bail.return;}Alarm alarm = null;// Grab the alarm from the intent. Since the remote AlarmManagerService// fills in the Intent to add some extra data, it must unparcel the// Alarm object. It throws a ClassNotFoundException when unparcelling.// To avoid this, do the marshalling ourselves.final byte[] data = intent.getByteArrayExtra(Alarms.ALARM_RAW_DATA);if (data != null) {Parcel in = Parcel.obtain();in.unmarshall(data, 0, data.length);in.setDataPosition(0);alarm = Alarm.CREATOR.createFromParcel(in);}if (alarm == null) {Log.v("wangxianming", "Failed to parse the alarm from the intent");// Make sure we set the next alert if needed.Alarms.setNextAlert(context);return;}// Disable the snooze alert if this alarm is the snooze.Alarms.disableSnoozeAlert(context, alarm.id);// Disable this alarm if it does not repeat.if (!alarm.daysOfWeek.isRepeatSet()) {Alarms.enableAlarm(context, alarm.id, false);} else {// Enable the next alert if there is one. The above call to// enableAlarm will call setNextAlert so avoid calling it twice.Alarms.setNextAlert(context);}// Intentionally verbose: always log the alarm time to provide useful// information in bug reports.long now = System.currentTimeMillis();// Always verbose to track down time change problems.if (now > alarm.time + STALE_WINDOW) {Log.v("wangxianming", "Ignoring stale alarm");return;}// Maintain a cpu wake lock until the AlarmAlert and AlarmKlaxon can// pick it up.AlarmAlertWakeLock.acquireCpuWakeLock(context);/* Close dialogs and window shade */Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);context.sendBroadcast(closeDialogs);// Decide which activity to start based on the state of the keyguard.Class c = AlarmAlert.class;KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);if (km.inKeyguardRestrictedInputMode()) {// Use the full screen activity for security.c = AlarmAlertFullScreen.class;}// Play the alarm alert and vibrate the device.Intent playAlarm = new Intent(context,AlarmAlertFullScreen.class);playAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);playAlarm.addFlags(FLAG_ACTIVITY_NEW_TASK);context.startActivity(playAlarm);// Trigger a notification that, when clicked, will show the alarm alert// dialog. No need to check for fullscreen since this will always be// launched from a user action.Intent notify = new Intent(context, AlarmAlert.class);notify.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);PendingIntent pendingNotify = PendingIntent.getActivity(context,alarm.id, notify, 0);// Use the alarm's label or the default label as the ticker text and// main text of the notification.String label = alarm.getLabelOrDefault(context);
//        Notification n = new Notification(R.drawable.stat_notify_alarm,
//                label, alarm.time);
//        n.setLatestEventInfo(context, label,
//                context.getString(R.string.alarm_notify_text),
//                pendingNotify);Notification.Builder builder = new Notification.Builder(context);Notification n = builder.setContentTitle(label).setSmallIcon(R.drawable.stat_notify_alarm).setContentText(context.getString(R.string.alarm_notify_text)).setContentIntent(pendingNotify).build();n.flags |= Notification.FLAG_SHOW_LIGHTS| Notification.FLAG_ONGOING_EVENT;n.defaults |= Notification.DEFAULT_LIGHTS;// NEW: Embed the full-screen UI here. The notification manager will// take care of displaying it if it's OK to do so.Intent alarmAlert = new Intent(context, c);alarmAlert.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);alarmAlert.setFlags(FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_NO_USER_ACTION);n.fullScreenIntent = PendingIntent.getActivity(context, alarm.id, alarmAlert, 0);// Send the notification using the alarm id to easily identify the// correct notification.NotificationManager nm = getNotificationManager(context);nm.notify(alarm.id, n);

这里主要使用广播接收者,来监听系统时间。如果时间到则发送通知,唤醒系统响铃。

如有需要可以私信 A18125287959

下载链接:https://download.csdn.net/download/coosea128/13761652

Android 闹钟app 课程设计相关推荐

  1. android 优秀app界面设计,基于Android系统的App界面设计.doc

    基于Android系统的App界面设计 摘 要:智能手机时代的来临改变了大多数人的生活习惯,时至今日智能手机已经成为了人们工作生活中的一部分,在工作生活中发挥着重要的作用.App作为智能手机应用程序的 ...

  2. 闹钟定时设计c语言编程,单片机定时闹钟(课程设计).docx

    单片机定时闹钟(课程设计) PAGE \* MERGEFORMAT10 绪 论 摘要: 单片机是一种集成在电路芯片,是采用超大规模集成电路技术把具有数据处理能力的中央处理器CPU随机存储器RAM.只读 ...

  3. Android打砖块课程设计报告,c+课程设计打砖块游戏0_毕业论文

    <c+课程设计打砖块游戏0_毕业论文>由会员分享,可在线阅读,更多相关<c+课程设计打砖块游戏0_毕业论文(7页珍藏版)>请在人人文库网上搜索. 1.课程设计报告课程名称:面向 ...

  4. Android闹钟APP

    项目描述: 该闹钟app实现了自由选择时间,设置闹钟模式:震动或铃声,也可以设置提示模式为每天或者单独选择提醒日期. 开发语言: java 技术框架: 无 开发工具: AndroidStudio2.2 ...

  5. android点餐课程设计,点餐系统课程设计报告

    点餐系统课程设计报告 目 录 一.系统说明3 二.系统功能3 三.系统结构流程图3 四.数据表结构4 五.主要表单功能4 六.所参与的功能模块及代码7 七.课程设计总结9 一.系统说明 酒店点餐管理系 ...

  6. Android学习别“走弯路”,android开发计算器课程设计

    3.几种基本类型,长度,边界 4.从 Iterator 到 Collection,再到 Set List Map(必问) 5.从以下几个角度理解学习:用法,具体实现类,线程安全性,底层数据存储结构,某 ...

  7. Android个人理财通课程设计,android课程设计-小组合作设计开发个人理财通项目.docx...

    2017 - 2018学年第_二_学期 <android>实践考核报告单 姓名 学号 班级 15网络1班 组别 第八组 组员 考核题目 小组合作设计开发个人理财通项目 考核目的 通过开发个 ...

  8. android天气时钟课程设计报告,安卓课程设计报告--《基于网络返参的安卓天气预测分析》...

    工程源码下载连接:http://download.csdn.net/detail/sailor_luo/9883334 目录 1.前言2 2.需求分析2 3.系统设计 一.系统流程2 二.函数流程3 ...

  9. 定时闹钟课程设计c语言,基于单片机89c52定时闹钟的课程设计.pdf

    前 言 20 世纪末,电子技术获得了飞速的发展.在其推动下,现代电子产品几乎渗透了 社会的各个领域,有力地推动了社会生产力的发展和社会信息化程度的提高.同时也 使现代电子产品性能进一步提高,产品更新换 ...

最新文章

  1. Python获取当前目录下所有文件的绝对路径并存储在文件中
  2. GDCM:gdcm::Keywords的测试程序
  3. 数字调制2ASK误码率分析matlab实现
  4. 自动化持续集成Jenkins
  5. Ubuntu连网的问题
  6. matlab化函数图像示例,Matlab绘制函数图像函数示例汇总
  7. linux C语言获取鼠标的绝对坐标/位置
  8. PS 渐变工具使用
  9. 【noip模拟题】华尔街的秘密
  10. html展示base64有长度限制,网页上的base64码太长?科普base64究竟是啥
  11. Path 贝塞尔曲线 练习 Demo
  12. 电加热炉温度控制系统的研究与设计
  13. 2022起重机司机(限门式起重机)考试题模拟考试题库及在线模拟考试
  14. Python pygame,精灵和精灵组
  15. 朋游风景:让智能手机成为贴身导游
  16. 三级网络技术备考重点之路由器配置及使用
  17. 鸿蒙系统会应用在平板电脑,华为将发布搭载鸿蒙系统的平板电脑-芯查查
  18. oracle 中处理标准差的问题
  19. ‘gbk‘ codec can‘t decode byte 0xa7 in position 40: illegal multibyte sequenc
  20. python的标准库turtle_Python标准库使用之使用turtle绘制奥林匹克五环

热门文章

  1. Linux:使用upower命令查看电池信息
  2. 如何看计算机加密方式,电脑常见的几种加密的方法
  3. 3D游戏物理开发引擎Panda3D基础
  4. Windows 11中Edge选单看不清显示异常的解决办法
  5. PN结——“耗尽层”?
  6. python判断按键是否按下_python – 如何检查键修饰符是否被按下(shift,ctrl,alt)?
  7. 基于Python(Django)+MongoDB实现的(Web)新闻采集和订阅系统【100010319】
  8. 基于SpringBoot点餐小程序的开发【前后端】
  9. 机器学习之中文处理:文言文还是白话文
  10. Office快捷键大全之二(Excel快捷键)