我正在尝试使用最新的FB SDK 4.4.1在我的Android应用中实现FB Share按钮 我已按照Facebook开发者页面上的所有步骤操作: https://developers.facebook.com/docs/sharing/android
只有成功发布内容后,我才想调用某个函数func1()。
当我点击FB Share按钮时,它会将我带到原生FB应用程序。
发生了什么:
会发生什么:
令人惊讶的是,当我在未安装FB原生应用程序的手机上尝试此操作时,会显示FB Web界面并正确调用onSuccess()和onCancel()。
提供以下代码:
FBShare.java
public class FBShare extends Activity {
private ShareButton shareButton;
CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fb_share);
callbackManager = CallbackManager.Factory.create();
shareButton = (ShareButton)findViewById(R.id.shareButton);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("My App")
.setContentDescription("My Desc")
.setContentUrl(Uri.parse("https://myapp.net"))
.setImageUrl(Uri.parse("https://myapp.net/12.png"))
.build();
shareButton.setShareContent(linkContent);
}
});
shareButton.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Result result) {
Log.i("FB Share button","success");
if (result.getPostId()!=null){
func1();
}
}
@Override
public void onCancel() {
Log.i("FB Share button","cancel");
}
@Override
public void onError(FacebookException error) {
Log.i("FB Share button","error");
}
});
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
fb_share.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/shareButton"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="10dp"
android:text="@string/fb_share_text"
android:textColor="@color/black"
android:textStyle="italic|bold" />
<com.facebook.share.widget.ShareButton
android:id="@+id/shareButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
任何人都可以帮助我吗?我做错了吗?