When trying to open a file with Intent getting 'Media not found' error

≡放荡痞女 提交于 2019-12-12 04:32:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!