Open Gallery Folder By Click On Notification

偶尔善良 提交于 2019-12-14 02:55:06

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/21486415/open-gallery-folder-by-click-on-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!