6

我正在开发一个日历小部件,当我手动更改日期时,我无法收到 DATE_CHANGED消息

问题是什么?

我在清单中的代码是:

<receiver android:name="com.widget.calendar.CalendarWidgetProvider">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        <action android:name="android.intent.action.DATE_CHANGED"/>
    </intent-filter>
    <!-- This specifies the widget provider info -->
    <meta-data android:name="android.appwidget.provider"
        android:resource="@xml/widgetinfo" />
</receiver>

我试图像这样接收它:

@Override
public void onReceive(Context ctx, Intent intent) {
    final String action = intent.getAction();
    if (action.equalsIgnoreCase("android.intent.action.DATE_CHANGED")) {
        Log.e(TAG, "Date changed.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    }
    super.onReceive(ctx, intent);
}

但是当我手动更改系统日期时,不会打印日志。

谢谢!

更新:

我用Intent.ACTION_TIME_CHANGED解决了这个问题,这确实是 DATE_CHANGED 的错误。

4

1 回答 1

8

使用此意图:

 <intent-filter>
        <action android:name="android.intent.action.TIME_SET"/>
 </intent-filter>

并收到:

@Override
public void onReceive(Context ctx, Intent intent) {
    final String action = intent.getAction();
    if (action.equalsIgnoreCase("android.intent.action.TIME_SET")) {
        Log.e(TAG, "Date changed.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    }
    super.onReceive(ctx, intent);
}
于 2012-07-12T07:50:40.867 回答