2014-11-06 106 views
0

我正在使用ShareActionProvider(android.widget.ShareActionProvider)共享簡單的文本。 它適用於Gmail,WhatsApp等,但不與Facebook ...ShareActionProvider不共享與意圖與Facebook的文本

它不共享附加到意圖的文本,而是它只是要求用戶寫一個新的職位。

如何解決這個問題?

這裏是我的代碼:

XML:

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<item android:id="@+id/action_share" 
    android:title="@string/action_share" 
    android:showAsAction="always" 
    android:actionProviderClass="android.widget.ShareActionProvider" /> 
</menu> 

的Java:

@Override 
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     inflater.inflate(R.menu.detailfragment, menu); 

     // Retrieve the share menu item 
     MenuItem share = menu.findItem(R.id.action_share); 
     // Get the provider and hold onto it to set/change the share intent. 
     mShareActionProvider = (ShareActionProvider) share.getActionProvider(); 

     // Attach an intent to this ShareActionProvider. You can update this at any time, 
     // like when the user selects a new piece of data they might like to share. 
     if (mShareActionProvider != null && mForecastStr != null) { 
      mShareActionProvider.setShareIntent(createShareIntent()); 
      Log.v(LOG_TAG, "mForecast: " + mForecastStr); 
      Log.v(LOG_TAG, "Intent: " + mShareActionProvider); 
     } else { 
      Log.d(LOG_TAG, "Share Action Provider is null?"); 
     } 
    } 


    public Intent createShareIntent() { 
     Intent shareIntent = new Intent(Intent.ACTION_SEND); 
     shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 
     shareIntent.setType("text/plain"); 
     shareIntent.putExtra(Intent.EXTRA_TEXT, mForecastStr); 

     return shareIntent; 
    } 

謝謝!

+0

請解釋一下,完全準確地,什麼手段「不與Facebook合作。」 – CommonsWare 2014-11-06 00:48:20

+0

對不起,我改正了。謝謝!! – Makoto 2014-11-06 01:09:57

回答

0

有一箇中間解決方案。這是真的FB不共享文本。他們說這是對用戶言論自由的攻擊。但是,你有一個解決方案。你可以傳遞一個鏈接。然後FB將「意圖」轉換爲圖像和鏈接,並將其添加到未來的響應中。但它留空用戶書寫空間... 例如嘗試:

shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");