简体   繁体   English

如何链接推送通知以打开已保存的图像

[英]how can i link Push notification to open the image that has been saved

in this scenario the user save image and he gets push notification,I want that user click on the notification then he should be directed towards the path where he has saved image. 在这种情况下,用户保存图像并收到推送通知。我希望该用户单击通知,然后将他引向他保存图像的路径。 how can i do it. 我该怎么做。 by addaction in notification or else ? 通过通知中的addaction还是其他?

private void saveImage() {
    ctime = Calendar.getInstance().get(Calendar.MILLISECOND);
    imageView.setDrawingCacheEnabled(true);
    bitmap = imageView.getDrawingCache();

//the path where image is stored
    file = new File(
            android.os.Environment.getExternalStorageDirectory(),"ZXMCO Picture");
    if (!file.exists()) {
        file.mkdirs();

    }
    f = new File(file.getAbsolutePath() + file.separator + "frm"
            + ctime + ".png");
    MediaScannerConnection.scanFile(this, new String[]{f.getPath()},
            null, new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                }
            });


    FileOutputStream ostream = null;
    try {
        ostream = new FileOutputStream(f);
        bitmap.compress(Bitmap.CompressFormat.PNG, 10, ostream);

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        ostream.flush();
        ostream.close();
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                "content://media/internal/images/media"));
        NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notify=new Notification.Builder
                (getApplicationContext()).setContentTitle("ZXMCO").setContentText("Image Saved Successfully").
                setContentTitle("ZXMCO").setSmallIcon(R.drawable.logo_64x43).build();
        notify.flags |= Notification.FLAG_AUTO_CANCEL;
        notif.notify(0, notify);
        Toast.makeText(getApplicationContext(), "Image saved",Toast.LENGTH_LONG).show();
    }

    catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

I am not sure, it will work or not ,You can use intent to go to the path of saved image, 我不确定它是否可以工作,您可以使用Intent转到已保存图像的路径,

Intent intent=new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(path)), "image/*");


        PendingIntent pendingIntent=PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

Now call this pending intent in Notification as:- 现在在通知中将此挂起的意图称为:-

notification= new NotificationCompat.Builder(context)
                .setContentTitle("Alarm service")
                .setWhen(System.currentTimeMillis())
                .setDefaults(Notification.DEFAULT_SOUND)
                .setAutoCancel(true)
                .addAction(R.drawable.go,"Go",pendingIntent)//to add action button
                .setContentIntent(pendingIntent).build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM