可变时间格式:"yyyy-MM-dd HH:mm:ss"

保存闹钟时间:

  • SimpleDateFormat df = new SimpleDateFormat("HH:mm");//设置日期格式

  • String thistime = df.format(new Date());

  • SharedPreferences sharedPreferences = getSharedPreferences("industryInfo", Context.MODE_PRIVATE); //私有数据

  • SharedPreferences.Editor editor = sharedPreferences.edit();//获取编辑器

  • editor.putString(“retime”, thistime);//名称 id

  • editor.commit();//提交

监听时间变化:

监听service

/*** 作者:created by meixi* 邮箱:13164716840@163.com* 日期:2018/9/27 09*/
public class Serview extends Service {/*** 广播接受者*/private BroadcastReceiver mBatInfoReceiver;private String TAG = "lgq--------------------";@Overridepublic void onCreate() {super.onCreate();initBroadcastReceiver();}/*** 注册广播*/private void initBroadcastReceiver() {final IntentFilter filter = new IntentFilter();// 屏幕灭屏广播filter.addAction(Intent.ACTION_SCREEN_OFF);//关机广播filter.addAction(Intent.ACTION_SHUTDOWN);// 屏幕亮屏广播filter.addAction(Intent.ACTION_SCREEN_ON);// 屏幕解锁广播
//        filter.addAction(Intent.ACTION_USER_PRESENT);// 当长按电源键弹出“关机”对话或者锁屏时系统会发出这个广播// example:有时候会用到系统对话框,权限可能很高,会覆盖在锁屏界面或者“关机”对话框之上,// 所以监听这个广播,当收到时就隐藏自己的对话,如点击pad右下角部分弹出的对话框filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);//监听日期变化filter.addAction(Intent.ACTION_DATE_CHANGED);filter.addAction(Intent.ACTION_TIME_CHANGED);filter.addAction(Intent.ACTION_TIME_TICK);mBatInfoReceiver = new BroadcastReceiver() {@Overridepublic void onReceive(final Context context, final Intent intent) {String action = intent.getAction();if (Intent.ACTION_SCREEN_ON.equals(action)) {Log.i(TAG, "screen on");} else if (Intent.ACTION_TIME_TICK.equals(action)) {//日期变化步数重置为0Log.i("lgq0000000000000000","日期变化步数重置为0===="+action);SharedPreferences share = getSharedPreferences("industryInfo", Activity.MODE_PRIVATE);String industryOne = share.getString("retime", "");//名称 获取idif (industryOne.equals(new SimpleDateFormat("HH:mm").format(new Date()))){//todo   闹钟到了}}}};registerReceiver(mBatInfoReceiver, filter);}@Nullable@Overridepublic IBinder onBind(Intent intent) {return null;}
}
<service android:name=".testt.Serview"><intent-filter><!-- 系统启动完成后会调用--><action android:name="android.intent.action.BOOT_COMPLETED" /><action android:name="android.intent.action.DATE_CHANGED" /><action android:name="android.intent.action.MEDIA_MOUNTED" /><action android:name="android.intent.action.USER_PRESENT" /><action android:name="android.intent.action.ACTION_TIME_TICK" /><action android:name="android.intent.action.ACTION_POWER_CONNECTED" /><action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /></intent-filter>
</service>
    /*** 开启计步服务*/private void setupService() {Intent intent = new Intent(this, Serview.class);
//        isBind = bindService(intent, conn, Context.BIND_AUTO_CREATE);startService(intent);}

Android 闹钟,实现demo相关推荐

  1. Android闹钟最终版【android源码闹钟解析】

    我以前写了个复杂闹钟的demo,参见Android闹钟[复杂版][大明进化十五] .但是里面的bug有一些,好多人留言,所以我就看看源码,找找原因?顺便把源码代码整理出来,弄成一个完整的可以运行的ap ...

  2. android 设备关机后还能在设定的闹钟时刻响起的功能如何实现,Android闹钟 AlarmManager的使用...

    Android闹钟 AlarmManager的使用 AlarmManager介绍 AlarmManager这个类提供对系统闹钟服务的访问接口. 你可以为你的应用设定一个在未来某个时间唤醒的功能. 当闹 ...

  3. QT 5.4.1 for Android Ubuntu QtWebView Demo

    QT 5.4.1 for Android Ubuntu QtWebView Demo 2015-5-15 目录 一.说明: 二.参考文章: 三.QtWebView Demo在哪里? 四.Qt Crea ...

  4. Android 抽屉效果Demo

    2019独角兽企业重金招聘Python工程师标准>>> Android 抽屉效果Demo. 转载:http://www.adobex.com/android/source/detai ...

  5. android闹钟延时,android闹钟定时启动延时或者直接不启动

    自己写的android闹钟功能,需要实现timepicker选择完成后将选择的时间设定为闹钟的启动时间,但是不管怎么改总是没法定时启动 alertDialog = new AlertDialog.Bu ...

  6. android 微信 demo,android微信分享demo

    [实例简介] android微信分享demo 开发实例源代码 [实例截图] [核心代码] android微信分享demo └── android微信分享demo └── wxshare ├── And ...

  7. Android学习小Demo(10)ToDoList的改进版之ViewPager显示多个图片

    在TodoList增强版的增加界面上,为了显示图片,我是挖了两块地方,放了两个ImageButton,来显示图片,而且限制了最多只能放两张图片.当两个View都放置图片之后,我就会把"Gal ...

  8. Android学习小Demo(10)ToDoList的加强版

    前两天去超市逛东西,问老板娘这个东西多少钱,那个东西多少钱,但是一两分钟后就搞混了,当时就想,我不是写了一个todo的吗,可以再拍照放上去,这样就有对比啦! 于是兴冲冲地赶回家,把功能给实现了,虽然这 ...

  9. Android学习小Demo(9)一个To Do List的实现

    记得看过一篇文章,是说一个人临走之前,列下了想做的最后100件事情,然后拿着这张便签,一件一件地去实现.又想起乔布斯说,如果今天是你的最后一天,你会怎么过? 我有很多事情想做,想写很多的文章,但是时间 ...

  10. Android闹钟设置的解决方案

    Android闹钟设置的解决方案 参考文章: (1)Android闹钟设置的解决方案 (2)https://www.cnblogs.com/common1140/p/5701716.html 备忘一下 ...

最新文章

  1. python pytorch 包的安装
  2. Rabbitmq-理论基础
  3. network package url_inaddr
  4. select的5中子句where,group by, havaing, order by, limit的使用顺序及实例
  5. h5网页中使用打电话功能
  6. unity 200.8m yoy_【Unity文档】Realtime GI介绍(一)
  7. LinkedHashMap 的理解以及借助其实现LRU
  8. arm学习笔记五(c/c++与arm汇编混合编程)
  9. 10gocm-gt;session3-gt;数据备份与恢复
  10. CS224n学习笔记1-nlp介绍和词向量
  11. Windows下Maven 环境配置
  12. Javascript的两种“单引号”
  13. vue-cli3的安装使用
  14. MacOS串口调试工具minicom配置
  15. [病毒木马] 什么是LSP劫持
  16. 基于MATLAB的PID控制器设计
  17. 基于django的视频点播网站开发-step15-项目部署 1
  18. 树莓派c语言读取dht11,树莓派直接读取 DHT11 温湿度的方法
  19. dns配置异常怎么修复_电脑出现dns错误不能上网怎么办?dns错误修复方法
  20. shell脚本实现俄罗斯方块

热门文章

  1. [css] 你有用过CSS预处理器吗?喜欢用哪个?原理是什么?
  2. 前端学习(2644):懂代码之header表头页之折叠功能
  3. 前端学习(2622):过滤器进行操作
  4. “约见”面试官系列之常见面试题第三十篇之计算机操作系统进程和线程区别
  5. 前端学习(1859)vue之电商管理系统电商系统之梳理项目结构
  6. 第四十期:十年生死两茫茫,Linux QQ突然复活!
  7. java学习(144):file常用方法1
  8. 计算机操作系统(2):OS的发展过程
  9. java学习(77):GUL下拉菜单框和滚动条
  10. vue element-ui级联选择器选中后下拉框自动收起