as mentioned in Facebook developers, the way to publish a story to Instagram is to use the following code. one of solutions as mentioned here suggests that it will be resolved once Instagram is restarted. although it isn't working with us
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
intent.setDataAndType(uri, "jpg");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra("content_url", "https://www.yallasolutions.com");
this.grantUriPermission(
"com.instagram.android", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
getPackageManager().getPackageInfo("com.instagram.android",0);
Log.e("test","instagram was found");
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
Log.e("test","instagram is not installed !!!!!!!!!!");
}
Activity activity = this;
if (activity.getPackageManager().resolveActivity(intent, 0) != null)
activity.startActivityForResult(intent, 0);
i have tried both ADD_TO_STORY and ADD_TO_FEED and both return same error.
Here is a reference to my manifest as well
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kareem.test">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:enabled="true"
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>