facebook / facebook-android-sdk

Used to integrate Android apps with Facebook Platform.
https://developers.facebook.com/docs/android
Other
6.16k stars 3.65k forks source link

Problem sharing Photo on phone #917

Closed RPCarter53 closed 3 years ago

RPCarter53 commented 3 years ago

With the version 9.0.0, it would appear that a Share Photo does not work on Phone's. Sharing on an Android tablet works as normal but phones not so good. The code we The code I use is below, I suspect that the line "if (shareDialog.canShow(content, ShareDialog.Mode.NATIVE)) " returns false. As I say, this works OK on tablet.

    final SharePhotoContent content;
    SharePhoto photo = new SharePhoto.Builder()
            .setBitmap(image)
            .setUserGenerated(true)
            .setCaption(description)
            .build();
    content = new SharePhotoContent.Builder()
            .addPhoto(photo)
            .build();

    final ShareDialog shareDialog = new ShareDialog(this);
    // ensure we post through native app.
    if (shareDialog.canShow(content, ShareDialog.Mode.NATIVE)) {
        shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {

            boolean haveErrored = false;

            @Override
            public void onSuccess(Sharer.Result result) {
                if (DEBUG_ON) Log.i(LOG_TAG, "fbShare:onSuccess ");
                //  Analytics
                AnalyticsHelper analyticsHelper = AnalyticsHelper.getInstance(ActivityBase.this);
                analyticsHelper.logShare(title, description);
            }

            @Override
            public void onCancel() {
                if (DEBUG_ON) Log.i(LOG_TAG, "fbShare:onCancel ");
            }

            @Override
            public void onError(FacebookException e) {
                if (DEBUG_ON) Log.e(LOG_TAG, "fbShare:onError " + e.toString());
                // we retry once
                if (!haveErrored) {
                    if (DEBUG_ON) Log.e(LOG_TAG, "fbShare:onError - Retrying");
                    haveErrored = true;
                    shareDialog.show(content);
                }
            }
        });

        // show share dialog to user
        shareDialog.show(content);
        didPost = true;
    }
linmx0130 commented 3 years ago

Hi @RPCarter53, thanks for raising the issue!

But for now I cannot reproduce the bug. Could you provide us with more information (like brand, model, permissions of fb apps) about the test device you're using?

RPCarter53 commented 3 years ago

Thanks for responding so promptly. As requested, a little more information. The phone on which this fails is a Pixel 2 with Android version 11. Facebook App version is 308.0.0.42.118. From the code shared above, shareDialog.canShow(content, ShareDialog.Mode.NATIVE) is returning false. If I ignore this and try to share anyway I get the error "Unable to show the provided content via the web or the installed version of the Facebook app. Some dialogs are only supported starting API 14." This may be an issue with the combination of libraries included as just stepping back versions of the Facebook share library does not appear to resolve the issue. The tablet on which the exact same version works is a Galaxy Tab A with android version 7.1.1. It has the same version of Facebook as the aforementioned Phone.

RPCarter53 commented 3 years ago

Further update. A Pixel 3 Emulator with Android 10, AppStore and FaceBook App - Our App Shares successfully.

A Pixel 3 Emulator with Android 11, AppStore and FaceBook App - Our App Fails to Share.

Everything is identical except for the Android version.

linmx0130 commented 3 years ago

I tested it with a Pixel 3 Emulator with Android 11, AppStore and Facebook App. But in my test app canShow() returns true and everything looks good.

Can you have a try on setting the mode to be AUTOMATIC and see what would happen?

RPCarter53 commented 3 years ago

The command shareDialog.canShow(content, ShareDialog.Mode.AUTOMATIC) is also returning false!

RPCarter53 commented 3 years ago

For completeness the full set of dependencies in this app are as follows

// Multidex required
implementation 'androidx.multidex:multidex:2.0.1'

// Import the BoM for the Firebase platform: Defines versions for Firebase imports
implementation platform('com.google.firebase:firebase-bom:26.6.0')

// Firebase Analytics
implementation 'com.google.firebase:firebase-analytics'

// cloud messaging (Amazon uses different solution)
googleImplementation 'com.google.firebase:firebase-messaging'
samsungImplementation 'com.google.firebase:firebase-messaging'

amazonCompileOnly files('libs/amazon-device-messaging-1.1.0.jar')

// android support library components
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.transition:transition:1.4.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.google.android.material:material:1.3.0'

implementation "androidx.lifecycle:lifecycle-process:2.3.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.3.0"

implementation "androidx.work:work-runtime:2.5.0"

// RX libraries
implementation 'io.reactivex.rxjava3:rxjava:3.0.11'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

// facebook share library
implementation 'com.facebook.android:facebook-share:9.0.0'

// Ad networks

//freeImplementation 'com.google.firebase:firebase-ads'com.google.android.gms:play-services-ads
freeImplementation 'com.google.android.gms:play-services-ads'
// Amazon Ad network
freeImplementation files('libs/amazon-ads-6.0.0.jar')

freeImplementation 'com.google.ads.mediation:facebook:6.3.0.0'
freeImplementation 'com.facebook.android:audience-network-sdk:6.3.0'

// In-App billing libraries
implementation files('libs/in-app-purchasing-2.0.76.jar')
implementation 'com.android.billingclient:billing:3.0.3'
implementation project(path: ':IAP6Helper')
implementation project(path: ':Utilities')
ghost commented 3 years ago

I got it . Thanks for information but we dont want message again please dont send any ok message10 Mar 2021 22:48 tarihinde Mengxiao Lin @.***> yazdı: Hi @RPCarter53, thanks for raising the issue! But for now I cannot reproduce the bug. Could you provide us with more information (like brand, model, permissions of fb apps) about the test device you're using?

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or unsubscribe.

linmx0130 commented 3 years ago

@RPCarter53 Thanks for providing us with the detailed information! It helps a lot! We can confirm now that it's caused by a change in Android 11 (API level 30). We're now actively working on addressing the issue.

linmx0130 commented 3 years ago

@RPCarter53 Thank you for raising this issue again!

For Android 11, you can add the following queries block into your AndroidMainfest.xml to solve the problem:

<manifest package="com.example.app">
    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
    </queries>
    ...
</manifest>

We will continue to work on this problem and find a better solution!

hust201010701 commented 3 years ago

Do you have a better solution now? I concern that maybe others queries block need to been added either.

linmx0130 commented 3 years ago

Hi @hust201010701 Thanks for raising the concern. Adding this queries block is enough to solve the sharing problem on Android 11.

rshchpkn commented 3 years ago

@linmx0130 Have the same issue but with queries block. On the lower Android version all works correctly Is there some new info regarding this issue?

linmx0130 commented 3 years ago

Hi @rshchpkn! Could you provide more information about how you add the queries block and which sharing features you are using?

If you only use "sharing to Facebook", the above code should fix the problem.

rshchpkn commented 3 years ago

@linmx0130 I'm using MessageDialog to share link. Here is part of my AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.app">
    <queries>
      <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
    </queries>

    ...

</manifest>
linmx0130 commented 3 years ago

Hi @rshchpkn, for Messenger, please add following provider:

      <provider android:authorities="com.facebook.orca.provider.PlatformProvider" />

Could you have a try?

rshchpkn commented 3 years ago

@linmx0130 It works good on Android 11 & 9. Many thanks 🙏 Maybe it worth to add to the troubleshooting part in the docs. What do you think?

linmx0130 commented 3 years ago

@rshchpkn Thanks for the advice! We will update our official document on http://developers.facebook.com soon!

wulongcd commented 2 years ago

Provider must set android:name and has not defalut name。so that i can not build the project,How are you fix this? Could you help me?