我正在使用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;
}
謝謝!
請解釋一下,完全準確地,什麼手段「不與Facebook合作。」 – CommonsWare 2014-11-06 00:48:20
對不起,我改正了。謝謝!! – Makoto 2014-11-06 01:09:57