问题
I download a file and save it as a temporary file using
File outputDir = context.getCacheDir();
File f = File.createTempFile(FILE_TYPE_PREFIX, "." + extension,outputDir);
f.exists() says that the file exists and as well I set f.setReadable(true, false); to be able to read it.
The I start a new Intent
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(f), mimeType);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
the f returns
/data/user/0/com.app.name/cache/PP_278545395.png
and after Uri.fromFile()
file:///data/user/0/com.app.name/cache/PP_278545395.png
As I try to open the file, it opens the Gallery but tells me "Media not found".
Any ideas why this issue exists?
回答1:
getCacheDir()
is part of internal storage for your app. Other apps do not have access to it. Use FileProvider
to publish that content to other apps.
来源:https://stackoverflow.com/questions/44639248/when-trying-to-open-a-file-with-intent-getting-media-not-found-error