DateTimeChangedReceiver

Posted adamli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DateTimeChangedReceiver相关的知识,希望对你有一定的参考价值。

package com.android.demo.lileidemo.listener;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;

import com.android.demo.lileidemo.MyApplication;
import com.android.demo.lileidemo.constant.AppConstants;

/**
* date: 04/22/2020.
* author: lilei.
*/
public class DateTimeChangedReceiver extends BroadcastReceiver {
private static final String TAG = AppConstants.APP_TAG + "DateTimeChangedReceiver ";
private Handler mWorker;
private static volatile DateTimeChangedReceiver mInstance;

public DateTimeChangedReceiver() {
mWorker = new Handler();
}

/**
* get Instance.
*
* @return instance.
*/
public static DateTimeChangedReceiver getInstance() {
if (mInstance == null) {
synchronized (DateTimeChangedReceiver.class) {
if (mInstance == null) {
mInstance = new DateTimeChangedReceiver();
}
}
}
return mInstance;
}

public void registerIviStateChangeListener() {
//LogUtil.d(TAG + "registerIviStateChangeListener()");
registerReceiver();
}

/**
* registerReceiver.
*/
private void registerReceiver() {
//LogUtil.d(TAG + "registerReceiver private");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_TIME_CHANGED);
intentFilter.addAction(Intent.ACTION_DATE_CHANGED);
MyApplication.getAppContext().registerReceiver(DateTimeChangedReceiver.getInstance(),
intentFilter);
}

@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())
|| Intent.ACTION_DATE_CHANGED.equals(intent.getAction()))) {
//LogUtil.d(TAG + "onReceive:" + intent.getAction());
doDateTimeChange();
}
}

private void doDateTimeChange() {
//when data time change should reInit timer.
//call reInitTimer();
}
}

以上是关于DateTimeChangedReceiver的主要内容,如果未能解决你的问题,请参考以下文章