应用widget工具包? [英] Application widget with bundle?
问题描述
我有应用程序插件,我希望将一些数据发送到连接到的PendingIntent,通过点击插件的意图。
这里是我的code
Hey guys, I have application widget, and I want to send some data to the intent that is attached to PendingIntent, by clicking the widget. here's my code
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, UpComingBDays.class);
if(bdaysAmount != 0){
Bundle bundle = new Bundle();
bundle.putIntegerArrayList("WIDGETIDS", tempAllIDS);
intent.putExtras(bundle);
System.out.println("bund insertedddddddddddddd.....................");
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
RemoteViews remoteView = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
remoteView.setTextViewText(R.id.widget_text, finalText4TextView);
remoteView.setOnClickPendingIntent(R.id.WidgetImageButton, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, remoteView);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
我认识总是外滩画报insertedddddddddd ......被印在目录下载,但目的的包是空。
I realize always "bund insertedddddddddd......" is printed on CatLog, but the intent's bundle is null.
什么是不正确的?我如何可以通过点击小工具发送数据。
PLZ不提供使用服务,我的code不具有任何事情。
非常感谢。
what is incorrect? how can i send data by clicking on widget. plz dont offer to use services as my code does not have anything with it. many thanks.
推荐答案
对不起了半年:)对于那些,谁就会发现这个帖子后回答后,当得到这样的问题:我发现,那FLAG_UPDATE_CURRENT是不够的:
Sorry for answering post after half a year :) For those, who will find this post when get this problem: I have found, that FLAG_UPDATE_CURRENT is not enough:
http://developer.android.com/reference/android/app/ PendingIntent.html
如果你需要更多的则1小部件与意图不同的捆绑数据,因为意图将overrwritten该标志将不起作用。
This flag will not work if you need more then 1 widget with different data in intents bundles, because Intent will be overrwritten.
要解决这个问题,你将需要更新的意图数据:
To fix this you will need to update intent data:
http://developer.android.com/guide/topics/appwidgets/ index.html的
// When intents are compared, the extras are ignored, so we need to embed the extras
// into the data so that the extras will not be ignored.
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
这篇关于应用widget工具包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!