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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…