如何使用Facebook SDK for Android在Facebook上分享图像?

时间:2015-11-21 05:57:52

标签: android facebook facebook-android-sdk

我想使用Facebook SDK将我的Android应用程序中的图像分享到Facebook。我的app中有一个名为Share的按钮。当我点击该按钮时,我的设备上的图像应该在Facebook上共享。这里问题是,当我点击按钮Facebook登录页面打开,但成功登录后Facebook将关闭,图像不共享。 任何人都可以建议我在哪里做错了吗?

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

我的Logcat输出如下。

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)

1 个答案:

答案 0 :(得分:0)

我得到了解决方案。这里的问题是我正在使用Fragment。 Facebook活动加载到WebView但共享未完成,Fragment仍为空。所以我从Fragment切换到Activity来解决我的问题。