android:监听系统时间更新
注册动态广播:时间改变监听/*** interval update time*/private void registerUpdateTimeReceiver() {//register time updateIntentFilter filter = new IntentFilter();filter.addAction(Intent.ACTION_TIME_TICK);filter.add.
·
- 注册动态广播:时间改变监听
/**
* interval update time
*/
private void registerUpdateTimeReceiver() {
//register time update
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
registerReceiver(mTimeUpdateReceiver, filter);
}
- 接受时间改变监听,处理事件
/**
* broad receive time update
*/
BroadcastReceiver mTimeUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
return;
}
String action = intent.getAction();
if (action == null || action.isEmpty()) {
return;
}
if (action.equals(Intent.ACTION_TIME_TICK)) {
//system every 1 min send broadcast
updateTimeUi();
} else if (action.equals(Intent.ACTION_TIME_CHANGED)) {
//system hand change time send broadcast
updateTimeUi();
}
}
};
更多推荐
已为社区贡献4条内容
所有评论(0)