zoukankan      html  css  js  c++  java
  • 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!---");
                }
    
            }

    此功能目前还不清楚用法。



  • 相关阅读:
    js_浏览器对象模型BOM---通过对象来抽象浏览器功能
    js_dom 之事件注册、移除 、pageX
    js组成之dom_dom对象样式操作及运用
    js_组成之DOM_dom对象的注册事件及属性操作
    js_字符串、数组常用方法及应用
    js_内置对象Date Math
    Caffe入门学习(代码实践)
    char和uchar区别
    c/c++中过滤文件路经 后缀
    shell中$(( )) 、 $( ) 、${ }的区别
  • 原文地址:https://www.cnblogs.com/lotusve/p/2525371.html
Copyright © 2011-2022 走看看