filipst filipst - 10 days ago 7
Android Question

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?

Answer

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);
        }
    });