2017-04-12 25 views
-1

我的Android應用程序中有一個Facebook Share按鈕。當我使用ImageButton或ImageView onClick時,它在調試模式下工作得非常好。但APK Build發佈類型失敗。com.facebook.share.widget.ShareButton在Android應用程序中被禁用

我在Stackoverflow問題的幫助下解決了這個問題,但最終導致FB Share按鈕被禁用。

嘗試添加下面的代碼,這裏有幾個答案,但仍然無法正常工作。

shareButton.setShareContent(linkContent); 

下面是我從哪裏調用onClick函數的XML。

<com.facebook.share.widget.ShareButton 
    android:id="@+id/imgFBShare" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/lblChangePasswordTitle" 
    android:layout_alignEnd="@+id/scrollView2" 
    android:layout_marginBottom="12dp" 
    android:onClick="shareFB" 
    app:srcCompat="@drawable/com_facebook_button_icon_blue" /> 

以下是我的onClick「shareFB」代碼。

public void shareFB (View view) { 
     callbackManager = CallbackManager.Factory.create(); 

     List<String> permissionNeeds = Arrays.asList("publish_actions"); 

     //this loginManager helps you eliminate adding a LoginButton to your UI 
     loginManager = LoginManager.getInstance(); 

     loginManager.logInWithPublishPermissions(this, permissionNeeds); 

     if (ShareDialog.canShow(ShareLinkContent.class)) { 
      Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); 
      Uri imageUri = Uri.parse(main_image_url); 

      ShareButton shareButton = (ShareButton) findViewById(R.id.imgFBShare); 

      ShareLinkContent linkContent = new ShareLinkContent.Builder() 
        .setContentTitle(short_headline) 
        .setContentDescription(
          short_description) 
        .setContentUrl(Uri.parse("http://mywebsite.com/android-app-download/")) 
        .setImageUrl(imageUri) 
        .build(); 

      shareButton.setShareContent(linkContent); 

      shareDialog.show(linkContent); 
     } 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int responseCode, Intent data) 
    { 
     super.onActivityResult(requestCode, responseCode, data); 
     callbackManager.onActivityResult(requestCode, responseCode, data); 
    } 

我錯過了什麼?

回答

0

經過詳細的每一個信息,我設法通過兩個非常簡單的步驟找出解決方案。

  1. 代替<com.facebook.share.widget.ShareButton在我Activity.xml,我恢復了<ImageView。這爲定義自己的圖像提供了更大的靈活性
  2. 從我shareFB我刪除ShareButton shareButton = (ShareButton) findViewById(R.id.imgFBShare);shareButton.setShareContent(linkContent);

現在工作完全正常!

相關問題