Reputation: 35
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 ?
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();
}
}
Upvotes: 1
Views: 801
Reputation: 1748
I am not sure, it will work or not ,You can use intent to go to the path of saved image,
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();
Upvotes: 3