多个实例的widget只更新最新插件多个、插件、实例、最新

由网友(扒拉拉小魔芋)分享简介:我有一个WidgetProvider和配置活动I have a WidgetProvider and an Configure Activity在Widget的启动会启动与配置活动,我将它设置通过自定义调用widgetprovider When the Widget is started it starts wi...

我有一个WidgetProvider和配置活动

I have a WidgetProvider and an Configure Activity

在Widget的启动会启动与配置活动,我将它设置通过自定义调用widgetprovider

When the Widget is started it starts with the configure activity and I set it up by making a custom call to the widgetprovider

(你会发现是从SDK实例教程)

(which you will notice is from the sdk tutorial examples)

 // Push widget update to surface with newly set prefix
              AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
              AwarenessWidget.updateAppWidget(context, appWidgetManager,
                      mAppWidgetId, position);

            // Make sure we pass back the original appWidgetId
            Intent resultValue = new Intent();
            resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
            setResult(RESULT_OK, resultValue);
            finish();

我通过控件ID的功能....小部件内创建一个这样的意图:

I pass the Widget ID to the function.... inside the widget I create a Intent like this:

  Intent configIntent = new Intent(context, Configure.class);
    configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

    PendingIntent pendingIntent = PendingIntent.getActivity
    (context, 0, configIntent,
    PendingIntent.FLAG_UPDATE_CURRENT);

    views.setOnClickPendingIntent(R.id.MainImage,pendingIntent);

    views.setImageViewResource(R.id.MainImage, lv_images[version]);

    appWidgetManager.updateAppWidget(appWidgetId, views);

我一直在引用的部件编号,甚至将其添加为一个额外的意图 但是当我得到两个这些小部件的主屏幕小部件I​​D总是引用最后放置的小部件ID上

I am always referencing the widget ID and even add it as a extra on the intent but when I get two of these widgets on the home screen the widget ID is always referencing the last placed widget ID

推荐答案

我也有类似的问题。只需添加到您配置的活动,在这里设置你的PendingIntent:

I had a similar problem. Just add this to your config activity, where you set your PendingIntent:

Uri data = Uri.withAppendedPath(
    Uri.parse(URI_SCHEME + "://widget/id/")
    ,String.valueOf(appWidgetId));
intent.setData(data);

变量URI_SCHEME是一个字符串,可以是任何你想..即 - ABCD这将导致每个插件都有一个唯一的PendingIntent

The variable URI_SCHEME is a String, and can be whatever you'd like.. ie - "ABCD" This causes each widget to have a unique PendingIntent.

阅读全文

相关推荐

最新文章