Sharing to Facebook Stories

*爱你&永不变心* 提交于 2019-12-14 01:26:58

问题


We were able to implement sharing to Instagram Stories, but not to Facebook Stories, following these instructions . Android is not able to find an app for the intent com.facebook.stories.ADD_TO_STORY, despite Facebook app being installed and updated. Has anybody been able to accomplish that?


回答1:


It might be too late but i thought to answer it if it can help people who might be facing issues in sharing to instagram without Intent Chooser dialog.


Facebook expects us to launch an intent chooser dialog to select from 4 -5 activities within facebook app itself that can handle com.facebook.stories.ADD_TO_STORY as action.


Nevertheless here is the code i used to launch the exact story editor screen from facebook app. It uses ACTION_SEND instead of com.facebook.stories.ADD_TO_STORY. So First define a fileprovider inside application tag in manifest

<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_provider_paths" />
        </provider>

Then keep file_provider_paths.xml inside xml folder in res directory. file_provider_paths.xml

<paths>
    <external-path
        name="share"
        path="/" />
</paths>

Then perpare a uri of file you want to share

File file = new File(imagePath);
Uri fileUri = FileProvider.getUriForFile(getApplicationContext(),getPackageName()+".fileprovider",file);

Then send intent to instagram as below

Intent storiesIntent = new Intent(Intent.ACTION_SEND);
storiesIntent.setComponent(new ComponentName("com.instagram.android", "com.instagram.share.handleractivity.CustomStoryShareHandlerActivity"));
storiesIntent.setDataAndType(uri, "image/*");//for background image
storiesIntent.putExtra("interactive_asset_uri", uri);//for sticker assets
storiesIntent.putExtra("content_url", "https://dexati.com/");
grantUriPermission("com.instagram.android", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(storiesIntent, 0);

Here we are making explicit call to the story editor activity of facebook app.



来源:https://stackoverflow.com/questions/50355564/sharing-to-facebook-stories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!