2014-11-06 108 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");