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);

            int id = NOTIFICATION_ID_PHOTO;
            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?

有帮助吗?

解决方案

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 = 
     PendingIntent.getActivity(context.getApplicationContext(),
                               id,
                               intent,
                               PendingIntent.FLAG_ONE_SHOT
     );

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));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top