分享按钮看起来已禁用

时间:2015-10-18 13:54:31

标签: android facebook share facebook-sdk-4.x

我正在尝试在我的应用程序中使用共享按钮,但它看起来好像已被禁用:

disabled share button

我已经初始化了sdk:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FacebookSdk.sdkInitialize(getApplicationContext());
}

我也有正确配置的清单,如文档建议: https://developers.facebook.com/docs/android/getting-started

视图中的按钮是这样的:

<com.facebook.share.widget.ShareButton
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/share"
              android:id="@+id/share_on_fb_button"
              bind:onClick="shareOnFBButtonClick"/>

可能是什么问题?为什么按钮被禁用?我应该在我的应用中实现登录功能吗?或者我只需要在设备上安装facebook应用程序?

1 个答案:

答案 0 :(得分:3)

请参阅com.facebook.share.widget.ShareButtonBase:

/**
 * Sets the share content on the button.
 * @param shareContent The share content.
 */
public void setShareContent(final ShareContent shareContent) {
    this.shareContent = shareContent;
    if (!enabledExplicitlySet) {
        internalSetEnabled(canShare());
    }
}

调用setShareContent启用shareButton,试一试:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_main);

    ShareButton fbShareButton = (ShareButton) findViewById(R.id.share_on_fb_button);
    ShareLinkContent content = new ShareLinkContent.Builder()
            .setContentUrl(Uri.parse("https://developers.facebook.com"))
            .build();
    fbShareButton.setShareContent(content);
}

注意: https://developers.facebook.com/docs/sharing/android

“当您实施共享时,您的应用不应预先填写任何要共享的内容。这与Facebook平台政策不一致,请参阅Facebook平台政策,2.3。”