2

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);

es0329
  • 1,366
  • 1
  • 18
  • 35
  • When you looked at the `Exception` that you got on Android 7.0, what did you learn? – CommonsWare Nov 17 '16 at 19:05
  • `E/ShareDialog: e.getLocalizedMessage >> file:///storage/emulated/0/870_90.mp4 exposed beyond app through ClipData.Item.getUri() E/ShareDialog: e.getCause >> null` – es0329 Nov 17 '16 at 19:14

2 Answers2

2

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);
}

See: android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

Community
  • 1
  • 1
Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491