Sharing Content (Android Development Patterns S2 Ep 6)

Android Developers · 43K views · 2016 · 3:42

Open on YouTube

Software (other)Software architecture & designtutorial

Why Stack Overflow recommends it

Stack Overflow users link it when explaining why file:// URIs are the wrong way to share files between Android apps and how FileProvider with content:// URIs fixes it.

Recommended by 3 people across 3 different months, 2016 to 2018.

What it is

A short episode of the Android Developers series on Android Development Patterns, presented by Ian Lake, about sharing text, HTML, files and images between apps. It covers ShareCompat for building share intents and FileProvider for granting URI-based access to files without storage permissions.

What people said

Recommends ianhanniballake · 2016-01 · Stack Overflow · on “Android ACTION_SEND event: "messaging failed to upload attachment"”

You are sending File URIs, with which Intent.FLAG_GRANT_READ_URI_PERMISSION does not apply and should not be used, as explained in this video [this video] and its accompanying blog post [LINK] . Other apps would need the storage permission to access your files. From the blog post: Instead, you can use URI permissions to grant other apps access to specific Uris. While URI permissions don’t work on file:// URIs as is generated by Uri.fromFile() , they do work on Uris associated with Content Providers [LINK] . Rather than implement your own just for this, you can and should use FileProvider [LINK] as explained in the File Sharing Training [LINK] .

Recommends cketti · 2016-02 · Stack Overflow · on “How to create intent / chooser to share external file?”

Don't use file:// URIs for sharing. It requires the receiving application to have the READ_EXTERNAL_STORAGE permission. Instead use FileProvider [LINK] with external-path to allow the receiving app to access the file through your content provider without requiring special permissions. To learn more, check out Ian Lake's video Sharing Content (Android Development Patterns S2 Ep 6) [this video] and the associated artice Sharing Content between Android apps [LINK] .

Recommends Simon · 2016-05 · Stack Overflow · on “Wrong Intent Uri data sharing audio files”

You should check out the official training docs for sharing [LINK] . You should always expect content:// uri's like content://Download/5348 . Because your suppose to call getContentResolver().openInputStream(uri) . So you can just end up using the ShareCompat.IntentReader [LINK] . Other recommended research to watch is: Sharing Content (Android Development Patterns S2 Ep 6) [this video] Forget the Storage Permission: Alternatives for sharing and collaborating (Big Android BBQ 2015) [LINK]

Cites Iulian Popescu · 2018-03 · Stack Overflow · on “Send Image via Share : Sends only a strange number and no file extension”

Well, as I already said, you can't share a drawable because of the Sandbox (it is only visible to you app). You can have a look here to see a few ways on how you can share it ( [this video] ), but you have to store the file in the external storage. An alternative would ve something like this [LINK] but this approach is more of a "hack" than an actual solution. The proper way to do it is to save it on external storage and then use the path to share it.