Android IntentLauncherAndroid to launch instagram app

Hi,

According to Instagram hooks the way to open instagram intent is using following code:

String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;

createInstagramIntent(type, mediaPath);

private void createInstagramIntent(String type, String mediaPath){

    // Create the new Intent using the 'Send' action.
    Intent share = new Intent(Intent.ACTION_SEND);

    // Set the MIME type
    share.setType(type);

    // Create the URI from the media
    File media = new File(mediaPath);
    Uri uri = Uri.fromFile(media);

    // Add the URI to the Intent.
    share.putExtra(Intent.EXTRA_STREAM, uri);

    // Broadcast the Intent.
    startActivity(Intent.createChooser(share, "Share to"));
}

Now I was trying to implement the same thing in react native. I tried the following code:

IntentLauncherAndroid.startActivityAsync('android.intent.action.SEND', {});

But it fails, how do I pass EXTRA_STREAM and other required details?

lol this is Java code for native Android :stuck_out_tongue_winking_eye:
No worries though, I gotchu: :blue_heart::fire::bomb:

import {Linking} from 'react-native';

 const sharePhoto = (uri) => {
    const encodedURL = encodeURIComponent(uri)
    const instagramURL = `instagram://library?AssetPath=${encodedURL}`
    Linking.openURL(instagramURL)
}

This does not work in Android. For android we have to use intents, thats why I pasted JAVA code.

Expo doesn’t support using Java code anywhere. React Native provides the Linking API which uses Intents on android. Learn more here: Linking · React Native

Instagram however doesn’t support deeplinking the same on android… You will have to do some digging to find how to share an image, but you can open the instagram app to a user on android like so:

 Linking.openURL(
    'http:/instagram.com/_u/baconbrix/#Intent;package=com.instagram.android;scheme=https;end',
  );

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.