Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to share story using instagram sdk intent

We are following the official documentation for sharing stories from app to instagram

https://developers.facebook.com/docs/instagram/sharing-to-stories/

Expected behavior was that when i try to share a story the story screen of instagram app should open with the image send in the intent. Actual behavior is the instagram app doesn't open and user stays on the same screen.

// Define image asset URI and attribution link URL
Uri backgroundAssetUri = "your-image-asset-uri-goes-here;"
String attributionLinkUrl = "https://www.my-aweseome-app.com/p/BhzbIOUBval/";

// Instantiate implicit intent with ADD_TO_STORY action,
// background asset, and attribution link
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
intent.setDataAndType(backgroundAssetUri, MEDIA_TYPE_JPEG);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra("content_url", attributionLinkUrl);

// Instantiate activity and verify it will resolve implicit intent
Activity activity = getActivity();
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
  activity.startActivityForResult(intent, 0);
}
like image 536
Mohammed Faiyyaz Khatri Avatar asked Nov 28 '19 12:11

Mohammed Faiyyaz Khatri


1 Answers

You can try this

private void shareToInstagram() {
    path = tvSelectMedia.getText().toString().trim();
    Intent intent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
    if (intent != null) {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setPackage("com.instagram.android");
        try {
            shareIntent.putExtra(Intent.EXTRA_STREAM, uri)));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        shareIntent.setType("image/jpeg");
        startActivity(shareIntent);
    } else {
        // bring user to the market to download the app.
        // or let them choose an app?
        intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("market://details?id=" + "com.instagram.android"));
        startActivity(intent);
    }
}

like image 79
raj kavadia Avatar answered Sep 21 '22 11:09

raj kavadia