我在触发 AppWidgetReciever 的 onEnabled 和 onDisabled 方法时遇到问题。我指定了操作,我还在 onRecieve 方法中记录了每个操作,但我得到的唯一两个操作是“APPWIDGET_UPDATE”和“APPWIDGET_DELETED”。我已经用谷歌搜索了这个解决方案,但不幸的是没有找到。这是我的代码:
清单部分:
<receiver android:name=".ScheduleWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
<action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIDGET_DELETED" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/provider_xml" />
</receiver>
提供者_xml:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="180dp"
android:minHeight="40dp"
android:updatePeriodMillis="60000"
android:initialLayout="@layout/widget_layout"
android:configure="org.zivkovic.schedule.ConfigurationActivity"
>
</appwidget-provider>
ScheduleWidgetProvider:
public class ScheduleWidgetProvider extends AppWidgetProvider {
{
Log.w("Schedule", "ScheduleWidgetProviderRequested");
}
@Override
public void onReceive(Context context, Intent intent) {
Log.w("Schedule", "On recieve " + intent.getAction());
super.onReceive(context, intent);
}
@Override
public void onEnabled(Context context) {
Log.w("Schedule", "OnEnabled called");
...
super.onEnabled(context);
}
@Override
public void onDisabled(Context context) {
Log.w("Schedule", "OnDisabled called");
...
super.onDisabled(context);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; i++) {
....
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
任何帮助表示赞赏。谢谢!