0

アプリウィジェットをテストしようとしていますが、次のようにマニフェストにレシーバーを登録しました。

    <receiver android:name=".MyUtilityWidget" android:label="@string/widget_name">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
        <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_config" />
    </receiver>

MyUtilityコード:

     public class MyUtilityWidget extends AppWidgetProvider {

      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

           my Main Code here.... (widget stuff)
   }

私のウィジェットは正常に起動して実行されます(したがって、コードはここから除外します)。しかし、放送受信機が機能しておらず、放送を受信して​​いません。実際、LogCatは、インテントが実行されないことを示しています。したがって、私のコードブロックはapkデプロイメントで1回だけ実行され、二度と実行されません(ウィジェットのテキストは表示されますが、設定したように30mごとに更新されることはありません)。

ここで設定...

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dip"
android:minHeight="72dip"
android:updatePeriodMillis="1800000"
android:initialLayout="@layout/widget_message"
/>

また、updatePeriodMillisは30分未満にすることはできませんか?これは、デバッグ時に非常に厄介な問題です。インテントが実行されたかどうかを確認するために、実行ごとに約30分待つ必要があるためです。

助けていただければ幸いです。

4

1 に答える 1

1

RemoteViewを介してウィジェットを取得し、それに応じて更新する必要があります。自動的に更新されるだけではありません。

次のようなものを試してください。

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this
                .getApplicationContext());
        ComponentName thisWidget = new ComponentName(getApplicationContext(),
                MyWidgetProvider.class);
        int[] allWidgetIds2 = appWidgetManager.getAppWidgetIds(thisWidget);
        final int N =allWidgetIds2.length;
        // Perform this loop procedure for each App Widget that belongs to this provider
        for (int i=0; i<N; i++) {
            int appWidgetId = allWidgetIds2[i];
            RemoteViews widgetView = new RemoteViews(getPackageName(), R.layout.widget_layout);
            widgetView.setTextViewText(R.id.some_text_view, "some text");
于 2012-06-21T01:51:56.497 に答える