0

这是我想要实现的目标: 带有 3 个按钮的小部件: 1. 查看文件夹 2. 添加项目 3. 添加项目并启动相机以将照片附加到项目。

我希望通过使用带有附加功能的 Intent 来实现 2&3,如果单击了第三个按钮,只需添加一个布尔额外的“照片”以保持真实,这是我的代码:

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附加内容后,我的附加值立即被新值覆盖,并且我总是在我的活动中 获得true和值。意图有效,所以我想只使用另一个意图动作就可以了,但我想了解这个 PendingIntent 事情是如何工作的。PHOTOpendingFolder

4

1 回答 1

1

我能够使用此方法的未记录功能来实现这一点:

public static PendingIntent getActivity (Context context, int requestCode, Intent intent, int flags)

从文档: requestCode Private request code for the sender (currently not used).

Apparently this code is currently used somehow. Supplying different requestCodes to this method calls allowed me to create different PendingIntents for the same widget.

于 2013-01-17T18:42:44.023 回答