Q:

How to share image on Facebook using Facebook SDK for Android?

I want to share image from my Android App to Facebook using Facebook SDK.I have one Button named Share in my app.when i clicked on that button the image, which is on my device, should be shared on Facebook.Here the problem is when i clicked on button Facebook LogIn page opens,but after successfully LoggedIn Facebook will close and image is not shared.
Can anyone suggest me where am i doing wrong?
FacebookSdk.sdkInitialize(getActivity());

callbackManager = CallbackManager.Factory.create();

List<String> permissionNeeds = Arrays.asList("publish_actions");

//this loginManager helps you eliminate adding a LoginButton to your UI
manager = LoginManager.getInstance();

manager.logInWithPublishPermissions(getActivity(), permissionNeeds);

manager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                Log.e("ShareMethod", "called");
                sharePhotoToFacebook();
            }

            @Override
            public void onCancel() {
                System.out.println("onCancel");
            }

            @Override
            public void onError(FacebookException exception) {
                System.out.println("onError1234");
            }
});    

private void sharePhotoToFacebook(){
        file1 = new File(path);
        bitmap1 = BitmapFactory.decodeFile(file1.getAbsolutePath());
        Log.e("Bitmap1",""+bitmap1);
        SharePhoto photo = new SharePhoto.Builder()
                .setBitmap(bitmap1)
                .build();

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

        ShareApi.share(content, null);
        Log.e("Sharing","Successful");
}

@Override
public void onActivityResult(int requestCode, int responseCode, Intent data)
{
        super.onActivityResult(requestCode, responseCode, data);
        callbackManager.onActivityResult(requestCode, responseCode, data);
}

My Logcat output is as follow.
11-21 12:57:06.248    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:06.269    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:06.276    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:08.582    1139-1171/com.example.omshiv.moviehub W/EGL_emulation﹕ eglSurfaceAttrib not implemented
11-21 12:57:08.582    1139-1171/com.example.omshiv.moviehub W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa0625d40, error=EGL_SUCCESS
11-21 12:57:08.598    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:08.599    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:08.613    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:08.642    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:08.650    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:08.664    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:08.688    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:08.691    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:08.703    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:08.739    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:08.740    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:08.762    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:08.776    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:08.798    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:08.822    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:08.833    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:08.867    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:08.901    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:08.905    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:08.908    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:08.925    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:08.949    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:08.950    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:08.953    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:09.079    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:09.080    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:09.099    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:09.127    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:09.129    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:09.152    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:09.155    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:09.155    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:09.169    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)
11-21 12:57:09.179    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44
11-21 12:57:09.199    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0
11-21 12:57:09.205    1139-1171/com.example.omshiv.moviehub E/eglCodecCommon﹕ **** ERROR unknown type 0x73000f (glSizeof,72)

A:

I got the solution. Here the problem is that I am using Fragment. Facebook Activity loads into WebView but Sharing is not done, Fragment remains empty. So I switched from Fragment to Activity which solved my problem.

