我在应用程序中使用Facebook sdk应用了Facebook共享对话框。共享有效,但响应不成功。
这是OnCreateView中的代码,用于在适配器中单击按钮后调用Facebook回调管理器。
mAdapter.SetOnShareClickListener(new PostListAdapter.OnShareClickListener() {
@Override
public void onItemClick(View view, int position, Post obj) {
//create callback
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Toast.makeText(getContext(), "Share Successful!", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(getContext(), "Opz...Share cancel!", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException error) {
Toast.makeText(getContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
Picasso.with(getContext()).load(obj.getThumbnail()).into(target);
}
});
这是活动结果的代码
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == PICK_IMAGE_REQUEST && data != null && data.getData() != null) {
Bitmap image = null;
try {
image = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.build();
if (ShareDialog.canShow(SharePhotoContent.class)) {
SharePhotoContent sharePhotoContent = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
shareDialog.show(sharePhotoContent);
}
}
}
}