Android widget可以';未收到日期更改消息
我正在开发一个日历小部件,当我手动更改日期时,我无法收到日期更改消息 有什么问题 我在清单中的代码是:Android widget可以';未收到日期更改消息,android,date,android-intent,widget,Android,Date,Android Intent,Widget,我正在开发一个日历小部件,当我手动更改日期时,我无法收到日期更改消息 有什么问题 我在清单中的代码是: <receiver android:name="com.widget.calendar.CalendarWidgetProvider"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <act
<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>
但是当我手动更改系统日期时,不会打印日志
谢谢
更新:
我用解决了这个问题,它实际上是一个日期错误。使用此意图:
<intent-filter>
<action android:name="android.intent.action.TIME_SET"/>
</intent-filter>
但这将导致耗尽电池电量,因为每当时间发生变化时,它会一次又一次地调用广播接收器。@Akki我已经测试过,除非我手动更改系统时间或日期,否则它不会发送此时间设置意图。所以这里的电池是安全的。:)所以当用户手动更改日期时,你想调用此接收器吗?@Akki是的,我现在正在做一个日历小部件。:)
<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);
}