【发布时间】:2015-05-14 21:15:23
【问题描述】:
我正在用一个 stackView 做一个小部件,我正在用 RemoteViewFactory 添加位图(图像)。
我的问题是当我想为每个图像(我在 stackView 中)做一个onClickPendingIntent() 时。我知道我必须改用setPendingIntentTemplate(),但是当我按下某个小部件的图像时,我不知道如何进入活动。
这就是我在小部件类中的onUpdate() 中创建待定意图模板的内容:
Intent templateIntent = new Intent(Intent.ACTION_VIEW);
templateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
PendingIntent templatePendingIntent = PendingIntent.getActivity(
context, 0, templateIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setPendingIntentTemplate(R.id.widget_stack_view,
templatePendingIntent);
这就是我在 RemoteViewsFactory 类中处理待定意图模板的内容:
public RemoteViews getViewAt(int index){
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.grid_item_layout);
rv.setImageViewBitmap(R.id.image, images.get(index).getImage());
Intent fillInIntent = new Intent();
fillInIntent.putExtra(Intent.EXTRA_TEXT, images.get(index).getTitle());
rv.setOnClickFillInIntent(R.id.image, fillInIntent);
return rv;
}
到目前为止,这个 fillInIntent.putExtra(Intent.EXTRA_TEXT, images.get(index).getTitle()); 正在使用手机向我展示“使用完整操作”,您可以在其中选择要打开的应用程序,但如果您看到我在 putExtra() 中输入的内容是一个字符串。但我想要的是打开一个活动,然后通过putExtra() 传递一个位图图像(images.get(index).getImage())
【问题讨论】:
标签: android android-intent android-pendingintent