简体   繁体   中英

Facebook share dialog not showing from fragment

I'm using the following code to share a url+image on facebook:

public void simpleShare(String toShare, Uri uriImage) {
        Log.d(TAG,"simpleShare, toShare: " + toShare + ", uri: " + uriImage);
        ShareDialog shareDialog = new ShareDialog(getActivity());

        ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setImageUrl(uriImage)
                .setContentUrl(Uri.parse(toShare))
                .build();

        shareDialog.show(linkContent);

    }

This code is inside a class that extends DialogFragment. The facebook dialog is showing correctly if called from an Activity, but it's not working if called from a Fragment. This is happening only on Android 4, not on Android 5 (ie on Android 5 is working fine even from the fragment). Any idea why is it happening? I can assure that the call from activity or fragment are exact the same, I used the log to compare them.

Thanks!

try with the code: instead of getActivity use the class, and remove the imageurl parse into contentur first

ShareLinkContent content = new ShareLinkContent.Builder()
                .setContentUrl(Uri.parse(url))
                .setQuote(msg)
                .build();

        if (ShareDialog.canShow(ShareLinkContent.class)) {
            ShareDialog.show(activity, content);
            result.success("success");
        }

the new facebook SDK change some ways to make the dialog share run, and they dont give us many documentation about and how

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM