2015年12月9日 星期三

Share action Provider

for lower version


how to make a share intent

http://developer.android.com/training/sharing/send.html
https://guides.codepath.com/android/Sharing-Content-with-Intents




<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/menu_item_share"
        app:showAsAction="ifRoom"
        android:title="Share"
        app:actionProviderClass="android.support.v7.widget.ShareActionProvider" />
    ...

</menu>
special problem:
create share provider and add the intent at the first time

he
getMenuInflater().inflate(R.menu.detail, menu);
MenuItem shareactionItem = menu.findItem(R.id.menu_item_share2);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareactionItem);
String showString = getIntent().getStringExtra(Intent.EXTRA_TEXT)+"#SunshineApp";
//make the share intent
Intent shareIntent=new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT,showString);
shareIntent.setType("text/plain");
mShareActionProvider.setShareIntent(shareIntent);
re

when send:
add again


Intent shareIntent=new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT,showString);
shareIntent.setType("text/plain");
mShareActionProvider.setShareIntent(shareIntent);

If don’t setShareIntent  immediately after the mShareActionProvider , it doesn’t work