Pick the fix
Sharing a PDF with Uri.fromFile(file) crashes. What's the fix?
Hint 1 of 1
Which URI scheme can be shared across apps?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Get a content:// URI from FileProvider and grant read permission
Correct. file:// URIs can't be shared across apps since Android 7.
Why not the others?
- B Request MANAGE_EXTERNAL_STORAGE. That's a broad permission Play restricts, and doesn't fix the URI type.
- C Copy the PDF to a public folder first. Still a file:// URI, and leaks the file.
- D Use an implicit intent with ACTION_VIEW. The URI type is the problem, not the action.