android 监听系统时区变化,日期变化,时间变化
2015-06-16 10:43
597 查看
android 监听系统时区变化,日期变化,时间变化
1. 监听时区变化:配置:
<receiver android:name="com.gionee.ui.DateTimeReceiver"> <intent-filter> <action android:name="android.intent.action.TIMEZONE_CHANGED"/> </intent-filter> </receiver>
private static final String ACTION_TIMEZONE_CHANGED = Intent.ACTION_TIMEZONE_CHANGED; @Override public void onReceive(Context context, Intent intent) { if (DBG) { Log.d(LOG_TAG, "---onReceive() start!---"); } String action = intent.getAction(); if (ACTION_TIMEZONE_CHANGED.equals(action)) { if (DBG) { Log.d(LOG_TAG, "---TIMEZONE_CHANGED!---"); } } if (DBG) { Log.d(LOG_TAG, "---onReceive() end!---"); } }
2. 监听日期变化
配置:
<action android:name="android.intent.action.DATE_CHANGED" />
private static final String ACTION_DATE_CHANGED = Intent.ACTION_DATE_CHANGED; @Override public void onReceive(Context context, Intent intent) { if (DBG) { Log.d(LOG_TAG, "---onReceive() start!---"); } String action = intent.getAction(); if (ACTION_DATE_CHANGED.equals(action)) { if (DBG) { Log.d(LOG_TAG, "---DATE_CHANGED!---"); } } if (DBG) { Log.d(LOG_TAG, "---onReceive() end!---"); } }
3. 监听时间变化
配置:
<action android:name="android.intent.action.TIME_SET" />
private static final String ACTION_DATE_CHANGED = Intent.ACTION_DATE_CHANGED; private static final String ACTION_TIME_CHANGED = Intent.ACTION_TIME_CHANGED; @Override public void onReceive(Context context, Intent intent) { if (DBG) { Log.d(LOG_TAG, "---onReceive() start!---"); } String action = intent.getAction(); if (ACTION_DATE_CHANGED.equals(action)) { if (DBG) { Log.d(LOG_TAG, "---DATE_CHANGED!---"); } } if (ACTION_TIME_CHANGED.equals(action)) { if (DBG) { Log.d(LOG_TAG, "---TIME_CHANGED!---"); } } if (DBG) { Log.d(LOG_TAG, "---onReceive() end!---"); } }
说明:
1.配置<action android:name="android.intent.action.TIME_SET" />,可同时监听日期,时间的变化。 2.单独监听时间变化的配置,目前不了解。 3.配置中还可<action android:name="android.intent.action.TIME_TICK" />,代码中可
private static final String ACTION_TIME_TICK = Intent.ACTION_TIME_TICK; if (ACTION_TIME_TICK.equals(action)) { if (DBG) { Log.d(LOG_TAG, "---TIME_TICK!---"); } }
此功能目前还不清楚用法。
相关文章推荐
- Android设备各种使用尺寸整理
- android闹钟实现原理
- android自动化测试解决跨进程通信问题
- android按钮旋转简单实现
- Android webView 实现与JS
- [Android] AS 中 Gradle 配置运行浅析
- [Android] 环境配置之Android Studio开发NDK
- Android Studio Rendering Problems不能显示xxx.xml布局文件
- Android:控件AutoCompleteTextView 自动提示
- android sdk 原版 百度盘分享
- android studio 更新 Gradle错误解决方法
- Android程序退出,杀掉进程
- Android内存优化之封装九宫格
- Android应用Activity、Dialog、PopWindow、Toast窗口添加机制及源码分析
- Android Studio 导.so文件简单、高效的方法
- Android中使用Handler造成内存泄露的分析和解决
- Android使用ViewPager实现滚动广告解决OOM小技巧
- Android getevent用法
- Android 学习笔记之五大布局
- Android ADB 端口占用问题解决方案