1

ホーム画面ウィジェットを作成しようとしています。ウィジェットにはTextViews2 つといくつかありImageButtonsます。1 つは更新用で、2 番目は設定ウィンドウを開くためのものです。

問題は、Android 4.2.2 では動作し、Android 2.3.3 では動作しないことです。

すべてがうまく見えます。しかし、ボタンを押しても機能しません。最も興味深いのは、ウィジェットの最初のインスタンスでのみ発生していることです。2 番目が追加されると、すべて正常に動作します。

これは私のコードの一部であり、更新に使用されますが、現時点では Android 2.3.3 では確実に機能していません。

@Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds)
    {
        Log.i(TAG, "onUpdate");
        // Get all widgets ids
        ComponentName thisWidget = new ComponentName(context,
                DataAppWidgetProvider.class);
        int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);

        Log.d(TAG, "widgets id: " + allWidgetIds.length);

        for (int widgetId : allWidgetIds)
        {
            Log.d(TAG, "Widget: " + widgetId);
            // Get remote view
            RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                    R.layout.widget_layout);

            refreshIntentSend(context, remoteViews, allWidgetIds, widgetId);
            appWidgetManager.updateAppWidget(widgetId, remoteViews);
        }

        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }

    /**
     * Set up and add intent to button to refresh given widget
     */
    private void refreshIntentSend(Context context, RemoteViews remoteViews,
            int[] allWidgetIds, int widgetId)
    {
        Intent i = new Intent(context, DataAppWidgetProvider.class);
        i.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        PendingIntent pi = PendingIntent.getBroadcast(context,0, i,PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.imb_refresh,pi);
        Log.d(TAG, "refresh: " + widgetId + " remoteViews: " + remoteViews);
    }

イムはImageButton

誰かがここで何か間違っていると思いますか?

編集:

onReceive をチェックインすると、非常に興味深い結果が得られます。次のようになっている場合:

@Override
    public void onReceive(Context context, Intent intent)
    {
        Log.d(TAG,"intent: " + intent.getAction());
        super.onReceive(context, intent);
    }

またはこのように:

@Override
    public void onReceive(Context context, Intent intent)
    {
        Log.d(TAG,"intent: " + intent.getAction());
        if(AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(intent.getAction()))
        {
            Log.d(TAG,"Action");
        }
        super.onReceive(context, intent);
    }

LogCat は次のようになります。

DataAppWidgetProvider(411): intent: android.appwidget.action.APPWIDGET_UPDATE
DataAppWidgetProvider(411): Action

オーバーライドがない場合、または superonReceiveの後である場合onUpdateは、まったく呼び出されません。

4

1 に答える 1

0

Open androidの問題のようです

http://code.google.com/p/android/issues/detail?id=8889

回避策 -- エミュレータで CTRL + F11 キーを押すか、デバイスの向きを変更します

于 2013-08-21T12:52:36.440 に答える