Reputation: 1432
Following Instagram's video sharing Android Intent. Trivial edit to bypass a chooser and launch Instagram directly. See Gist of relevant code and adb output.
Kit Kat device works as intended, however Nougat device falls to Line#20, launching Play Store, as if Instagram isn't installed.
On both devices Line#14 of ShareDialog's startInstagram() does present a chooser of video-sharing capable apps, including Instagram.
Related code for sharing an image with this same approach works as intended on both devices.
UPDATE 1: Implementing the new ContentProvider approach makes Instagram crash upon launching the share Intent. I'll test sharing video to another social network to see if that works.
UPDATE 2: Turns out Instagram doesn't play nice with
share.setDataAndType(contentUri, "video/*");
.
Setting them seperately, put everything in working order.
share.setType("video/*");
share.putExtra(Intent.EXTRA_STREAM, contentUri);
Upvotes: 2
Views: 2449
Reputation: 38121
Logging the exception on your gist on Android Nougat reveals the problem:
android.os.FileUriExposedException: file:///storage/emulated/0/test.mp4 exposed beyond app through ClipData.Item.getUri()
On Android Nougat you will need to use a provider:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri contentUri = FileProvider.getUriForFile(getContext(), "com.your.package.fileProvider", newFile);
intent.setDataAndType(contentUri, type);
}
Upvotes: 2
Reputation: 1006614
That would appear to be a FileUriExposedException
. If your targetSdkVersion
is 24 or higher, you cannot use Uri.fromFile()
or other file
Uri
values in an Intent
or other places (e.g., setSound()
on a `Notification).
Use FileProvider
to serve your file via a ContentProvider
.
Upvotes: 1