Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android widget can't receive the DATE_CHANGED message

I am developing a calendar widget, and I can't receive the DATE_CHANGED message when I changed the date MANUALLY.

What is the problem?

My code in Manifest is :

<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 receive 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 is not print when I change the system date manually.

Thanks!

UPDATE:

I solved this with Intent.ACTION_TIME_CHANGED, It's really a bug of DATE_CHANGED.

like image 654
herbertD Avatar asked Jul 12 '12 04:07

herbertD


1 Answers

Use this intent:

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

And receive:

@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);
}
like image 55
herbertD Avatar answered Oct 13 '22 19:10

herbertD