Hoper Hoper - 1 year ago 117
Android Question

Open Gallery Folder By Click On Notification

I used this code to send notification.

public static void sendNotificationPhoto(Context context, Class<?> activityTarget)
Log.i( TAG , "Send Photo Notification");

NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notifyDetails = new Notification(R.drawable.ic_plusone_standard_off_client, "New Alert!", System.currentTimeMillis());
Intent intent = new Intent(context, activityTarget);

String contentText = "Slave Picture Is Now Available!";

PendingIntent contentIntent = PendingIntent.getActivity(context.getApplicationContext(), id, intent, PendingIntent.FLAG_ONE_SHOT);
notifyDetails.setLatestEventInfo(context.getApplicationContext(), context.getString(R.string.app_name), contentText, contentIntent);
mNotificationManager.notify(id, notifyDetails);

But now i don't need to open another activity but a specific Gallery's folder. Is it possibile with notification?

Answer Source

You can do this by

Intent intent = new Intent(Intent.ACTION_VIEW,ImageUri);
ImageUri = "content://media/external/images/media/1210"`

Call this intent in pendingIntent

PendingIntent contentIntent = 

The above Imageuri is for representation. This worked for me after several tries with other options. This intent doesnot work if you supply file.getpath or file.getabsolutepath

I've tried using Uri.fromFile and it worked:

intent = new Intent(Intent.ACTION_VIEW,Uri.fromFile(fileName));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download