我尽量让我的广播检查,如果时间改变或不是因为我要检查的时间每一分钟我把这个
android.intent.action.TIMEZONE_CHANGED android.intent.action.TIME_SET android.intent.action.TIME_TICK
但它不工作,我能做些什么。
//use these intent filter
s_intentFilter = new IntentFilter();
s_intentFilter.addAction(Intent.ACTION_TIME_TICK);
s_intentFilter.addAction(Intent.ACTION_TIME_CHANGED);
}
//实现广播:
private final BroadcastReceiver m_timeChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_TIME_CHANGED) ||
action.equals(Intent.ACTION_TIMEZONE_TICK)) {
// your work
}
}
};
//注册接收机:
public void onCreate()/onResume {
super.onCreate();
registerReceiver(m_timeChangedReceiver, s_intentFilter);
}
//并注销它:
public void onDestroy()/onPause {
super.onDestroy();
unregisterReceiver(m_timeChangedReceiver);
}