Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

Android 10 ACTION_VIEW won't show images outside scoped-storage

I've an image located at /storage/emulated/0/DCIM/Camera/xyz.jpg And I want to open this image using ACTION_VIEW from my app. The code I'm using is

File file = new File("/storage/emulated/0/DCIM/Camera/xyz.jpg");
Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/jpeg");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

My provider paths have

<external-path name="external_files" path="." />

The above intent shows a picker to select gallery/photos app and system's gallery app gives a blank white screen with error File format isn't supported or files are corrupted while photos app just hangs on the loading screen.

So my question is: Is it possible to directly open a file(outside scoped storage) using ACTION_VIEW? Or Do I have to first copy the file to scoped storage and then show it with ACTION_VIEW?

Answer: It's not possible to use ACTION_VIEW to open files outside scoped storage. It's also not possible to copy the file since we don't have access to it. So, we can either use ACTION_OPEN_DOCUMENT to let user choose the file or we can copy the files to scoped storage and keep using ACTION_VIEW.

question from:https://stackoverflow.com/questions/65847534/android-10-action-view-wont-show-images-outside-scoped-storage

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...