Android系统日期更改事件 [英] Android System date changed event

查看:437
本文介绍了Android系统日期更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经被问过很多次了,但是我找不到正确的方向。我已经注册了 BroadcastReceiver ,我想在 Android系统日期自动更改但未触发时触发该事件。我使用了以下方法:

I know this question has been asked many times but i am unable to find the right direction. I have registered BroadcastReceiver which I want to trigger when the Android System Date is changed automatically but its not firing. I have used the following approaches:

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_TIME_CHANGED);
registerReceiver(new DateTimeChangeReceiver (), intentFilter);



2-> AndroidManifest.xml



2-> AndroidManifest.xml

<receiver android:name=".DateTimeChangeReceiver ">
<intent_filter>
    <action android:name="android.intent.action.DATE_CHANGED"/>
</intent_filter>
</receiver>



DateTimeChangeReceiver



DateTimeChangeReceiver

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class DateTimeChangeReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Toast.makeText(context, "Date changed", Toast.LENGTH_SHORT).show();
    }

}

在两种情况下,接收者都不被触发。仅在设置手动时间时显示通知。有人可以指出我所缺少的内容吗?

In both cases, reciever is not being triggered. It only shows the notification when manually time is being set. Can anyone please point me out what I am missing?

预先感谢。

推荐答案

这些事件有广播。 ACTION_TIME_CHANGED和ACTION_DATE_CHANGED
ACTION文档位于 http://developer.android .com / reference / android / content / Intent.html#ACTION_DATE_CHANGED

There are broadcasts for those events. ACTION_TIME_CHANGED and ACTION_DATE_CHANGED ACTION docs at http://developer.android.com/reference/android/content/Intent.html#ACTION_DATE_CHANGED

潜在的错误和一些实现的详细信息,请参见 http://code.google.com/p/android/issues/detail?id=2880

A potential bug and some implementation details available at http://code.google.com/p/android/issues/detail?id=2880

这篇关于Android系统日期更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆