In one of the activities in My application clicking a button saves a gif in a folder that shows up when I open my gallery app. How can I open the file immediately after saving using an intent or something similar??
This is how I'm saving:
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File gifFile = new File(mediaStorageDir.getPath() + File.separator +
"GIF_"+ timeStamp + ".gif");
FileOutputStream outStream = null;
try{
outStream = new FileOutputStream(gifFile);
outStream.write(generateGIF());
outStream.close();
}catch(Exception e){
e.printStackTrace();
}
And this doesn't seem to work:
Uri fileUri = Uri.fromFile(gifFile);
startActivity(new Intent(Intent.ACTION_VIEW, fileUri));
答案 0 :(得分:1)
You need to use setDataAndType to pass the file URI and the type of the data :
Uri fileUri = Uri.fromFile(gifFile);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(fileUri,"image/gif");
startActivity(intent);