我正在尝试使用来自Facebook的this example从我的Android项目共享位图,但是

当我在我的项目中实现示例时-没有任何反应,没有警告,没有错误。这是我的代码:

    shareButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
            SharePhoto photo = new SharePhoto.Builder()
                    .setBitmap(image)
                    .build();
            SharePhotoContent content = new SharePhotoContent.Builder()
                    .addPhoto(photo)
                    .build();


            ShareDialog shareDialog = new ShareDialog(MainActivity.this);

            shareDialog.show(content);



        }
    });

最佳答案

您将必须注册一个回调以查看实际情况。

    public class MainActivity extends FragmentActivity {
        CallbackManager callbackManager;
        ShareDialog shareDialog;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            FacebookSdk.sdkInitialize(getApplicationContext());
            callbackManager = CallbackManager.Factory.create();
            shareDialog = new ShareDialog(this);
            shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
    // onSuccess method
    // onError method
    // onCancel method
 });
        }

然后在onActivityResult中调用SDK的callbackManager来处理响应:
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

10-08 17:24