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!---");
            }

        }

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



 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM