es0329 es0329 - 19 days ago 8
Android Question

Instagram's video sharing Android Intent

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: Implementing the new ContentProvider approach yields the following upon launching Instagram share Intent. I'll test sharing video to another social network to see if that works.

Instagram crash

Answer

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