0

How can I use

new SharePhoto.Builder()
    .setImageUrl(Uri uri)
    .build();

to share a file from internal storage to facebook stories? The documentation mentions adding

<provider android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
      android:name="com.facebook.FacebookContentProvider"
      android:exported="true"/>

to the AndroidManifest.xml, but it's not enough.

There is a method FacebookContentProvider.getAttachmentUrl() which gives a path that I tried to use to save my file there, but it doesn't work.

The error that I am getting from the Facebook SDK callback manager is the following.

Failed to copy sticker

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98

1 Answers1

0

There are some probable reasons for not getting the file properly.

The first one is, the Facebook SDK requires to have the file stored in your local storage with a valid Uri to the file. Hence, if the file is not actually stored in your local storage, that might be a problem.

And the other thing is setting up your application correctly so that it can access the files from the internal storage. I would like to recommend checking following things that might be missing in your application.

Check if you have the FileProvider in your AndroidManifest.xml like the following.

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

And you should have a file_provider_paths.xml file in your /res/xml folder which should contain the locations of your files like the following.

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path
        name="documents"
        path="Android/data/bd.com.ipay.android/files/Pictures" />
</paths>

Hope that helps!

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
  • Thank you for the answer! I have FileProvider set up and the file is being stored and the uri works when I share using Intent (https://developers.facebook.com/docs/sharing/sharing-to-stories/android-developers?locale=en_US), but the same Uri doesn't work when I try to share with their sdk. Do you know what can be the reason? – Viktoriia Chebotar Aug 01 '19 at 17:02
  • I just tried to pass network url and it also doesn't work and no result returned to CallbackManager. – Viktoriia Chebotar Aug 01 '19 at 17:29
  • Though this is an old post, I thought it might be useful. https://stackoverflow.com/a/23533347/3145960 – Reaz Murshed Aug 01 '19 at 20:14
  • I have a provider set in Manifest, otherwise, it wouldn't work with bitmap – Viktoriia Chebotar Aug 02 '19 at 08:58