Android widget cannot receive DATE_CHANGED message

I am developing a calendar widget and I cannot receive the DATE_CHANGED message when I changed the date of MANUALLY .

What is the problem?

My code in the manifest:

<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>

And I tried to get it like this:

@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);
}

But the log does not print when I manually change the system date.

Thank!

UPDATE:

I solved this with Intent.ACTION_TIME_CHANGED . This is really a DATE_CHANGED error.

+5
source share
1 answer

Use this intention:

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

And get:

@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);
}
+7
source

All Articles