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

时间:2016-12-14 11:02:48

标签: android push-notification

在这种情况下,用户保存图像并获得推送通知,我希望用户点击通知,然后他应该指向他保存图像的路径。我该怎么做。通过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();
    }

}

1 个答案:

答案 0 :(得分:1)

我不确定,它是否有效,您可以使用意图转到已保存图像的路径,

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

现在将通知中的此待处理意图称为: -

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