0

これが別のスレッドで回答されるかどうかはわかりませんが、しばらく回答を探していましたが、見つかりませんでした.

30 分ごとにテキストを表示するアプリ ウィジェットを実装していますが、ウィジェットをクリックするまで更新されませんでした。これが私のonUpdateメソッドです:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) 
      {
            // Get all ids
            ComponentName thisWidget = new ComponentName(context, MyWidgetProvider.class);
            int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
            Calendar getToday = Calendar.getInstance();
            for (int widgetId : allWidgetIds) 
            {
                  int number = (new Random().nextInt(100));

                  RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
                  // Set the text
                  String n = ""+number;
                  remoteViews.setTextViewText(R.id.update, n);
                  remoteViews.setTextColor(R.id.update, Color.BLUE);

                  // Register an onClickListener
                  Intent intent = new Intent(context, MyWidgetProvider.class);

                  intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                  intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

                  PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                  remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
                  appWidgetManager.updateAppWidget(widgetId, remoteViews);

            }

私のコードの問題は何ですか? 誰か助けてくれませんか。前もって感謝します

追加した :

<appwidget-provider 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:updatePeriodMillis="110000" 
    android:initialLayout="@layout/widget_layout" 
    android:minHeight="72dp"
    android:minWidth="300dp">
</appwidget-provider>
4

1 に答える 1

2

updatePeriodMillis でより頻繁な間隔が指定されていても、更新は 30 分ごとに 1 回しか行われません。AppWidgetProviderInfo docを参照してください。

于 2013-02-22T00:56:31.803 に答える