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.
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);
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:
public static PendingIntent getActivity (Context context, int requestCode, Intent intent, int flags)From the docs:
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
PendingIntentsfor the same widget.