filipst
filipst

Reputation: 1573

Facebook SDK 4.0 ShareDialog

I want to share an image from my Android app using facebook SDK 4.0. I got it to work with ShareDialog, but when the user doesn't have FB app installed, according to developers.facebook, SDK should use Web Share dialog instead:

In past versions of the SDK for Android, your app had to check for a native, installed Facebook app before it could open the Share Dialog. If the person didn't have the app installed, you had to provide your own code to call a fallback dialog.

Now the SDK automatically checks for the native Facebook app. If it isn't installed the Web Share dialog launches:

But nothing happens when I delete FB app and try to share.
Here is my code:

            ShareDialog shareDialog = new ShareDialog(this);

            BitmapFactory.Options bmOptions = new BitmapFactory.Options();

            bmOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;

            Bitmap image = BitmapFactory.decodeFile(imagePath, bmOptions);

            SharePhoto photo = new SharePhoto.Builder().setBitmap(image).build();

            SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();

            shareDialog.show(content, ShareDialog.Mode.AUTOMATIC);

EDIT

Is there a way to share a photo on facebook without facebook app installed?

Upvotes: 4

Views: 8099

Answers (4)

Laraib Azad
Laraib Azad

Reputation: 7

You can use share dialog to share photos.

Try this

 Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
                    SharePhoto.Builder photoBuilder = new SharePhoto.Builder();
                    photoBuilder.setBitmap(image);
                    photoBuilder.setCaption("HBD Caption");
                    final SharePhoto sharePhoto = photoBuilder.build();
                    SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(sharePhoto).build();
                    mShareDialog.show(content);

To add caption, you'll need to add publish permissions from facebook. If you wont do this, your image will get posted without a caption.

Reference: https://developers.facebook.com/docs/graph-api/reference/user/permissions/

Upvotes: 0

Aniket Dhandhukia
Aniket Dhandhukia

Reputation: 551

Try this:

I have faced the same trouble and I can say that that there is some trouble in SharePhotoContent API of facebook. You can share the image using ShareLinkContent.

ShareLinkContent linkContent = new ShareLinkContent.Builder()
                    .setImageUrl("Your url")
                    .build();
shareDialog.show(linkContent);

Upvotes: 0

filipst
filipst

Reputation: 1573

I have found the solution:

BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;

    Bitmap image = BitmapFactory.decodeFile(imagePathForShare, bmOptions);

    SharePhoto photo = new SharePhoto.Builder().setBitmap(image).build();

    SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();

    Toast.makeText(getApplicationContext(), getString(R.string.facebook_uploading), Toast.LENGTH_SHORT).show();

    ShareApi.share(content, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result)
        {
            Toast.makeText(getApplicationContext(), getString(R.string.facebookSuccessful), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel()
        {
            Log.v("FACEBOOK_TEST", "share api cancel");
        }

        @Override
        public void onError(FacebookException e)
        {
            Log.v("FACEBOOK_TEST", "share api error " + e);
        }
    });

Upvotes: 1

Please read SDK documents carefully. You cant share photo with sharedialog without Facebook App installed.

Refference : https://developers.facebook.com/docs/sharing/android

Photos

People can share photos from your app to Facebook with the Share Dialog or with a custom interface.

The photos must be less than 12MB in size

People need the native Facebook for Android app installed, version 7.0 or higher

Upvotes: 1

Related Questions