Android小工具和两个不同的PendingIntents [英] Android widget and two different PendingIntents
问题描述
下面就是我努力实现:
有3个按钮小工具:
1.查看文件夹
2.添加项目
3.添加项目,并启动相机附上照片的项目。
Here's what I'm trying to achieve: Widget with 3 buttons: 1. View folder 2. Add item 3. Add item and start a camera to attach a photo to the item.
我希望能达到2及通过使用额外的意向3,只需添加一个布尔额外的照片,如果被点击3号按钮来保存真实的,这是我的code:
I was hoping to achieve 2&3 by using an Intent with extras, just add a boolean extra "photo" to hold true if the 3rd button was clicked, here's my code:
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(Uri.parse("content://"
+ NoteProviderMetaData.AUTHORITY + "/folders/"
+ folderId));
intent.putExtra("photo", false);
intent.putExtra("kind", "NO PHOTO");
intent.setAction(Intent.ACTION_INSERT);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
views.setOnClickPendingIntent(R.id.imageButton2, pendingIntent);
Intent intentFolder = new Intent(Intent.ACTION_VIEW);
intentFolder.setData(Uri.parse("content://"
+ NoteProviderMetaData.AUTHORITY + "/folders/"
+ folderId + "/notes"));
PendingIntent pendingIntentFolder = PendingIntent.getActivity(this, 0, intentFolder, 0);
Intent intentPhoto = new Intent(Intent.ACTION_INSERT);
intentPhoto.setData(Uri.parse("content://"
+ NoteProviderMetaData.AUTHORITY + "/folders/"
+ folderId));
intentPhoto.putExtra("photo", true);
intentPhoto.putExtra("kind", "PHOTO");
intentPhoto.setAction(Intent.ACTION_INSERT);
PendingIntent pendingIntentPhoto = PendingIntent.getActivity(this, 0, intentPhoto, 0);
views.setOnClickPendingIntent(R.id.imageButton3, pendingIntentPhoto);
问题是,我创建后立即 pendingIntentPhoto
我的的PendingIntent
演员被新值覆盖,我总是得到在我的活动真正
和照片
值。 pendingFolder
意图的作品,所以我想这将是罚款只是用另一种意图行动,但我想明白这件事的PendingIntent是如何工作的。
The problem is that immediately after I create pendingIntentPhoto
my pendingIntent
extras are overridden by new values and I always get true
and PHOTO
values in my activity.
pendingFolder
intent works, so I guess it would be fine just to use another intent action but I'd like to understand how this PendingIntent thing works.
推荐答案
我是能够做到这一点使用这种方法的未公开的特性:
I was able to achieve this using this method's undocumented feature:
公共静态的PendingIntent getActivity(上下文的背景下,INT请求code,意图意图,诠释标志)
从文档:请求code私人请求,code发件人(当前未使用)。
显然,这code是目前使用某种方式。提供不同的请求codeS调用此方法使得我可以建立不同的 PendingIntents
为同一部件。
Apparently this code is currently used somehow. Supplying different requestCodes to this method calls allowed me to create different PendingIntents
for the same widget.
这篇关于Android小工具和两个不同的PendingIntents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!