For implementing user friendly share in action bar is made easy.
Add Menu item as follows
<item android:id="@+id/menu_item_share" app:showAsAction="always" android:title="Share" android:icon="@drawable/abc_ic_menu_share_mtrl_alpha" android:orderInCategory="3" android:actionProviderClass= "android.widget.ShareActionProvider" />
Update the share intent associated with that action item. Here's an example:
private ShareActionProvider mShareActionProvider; ... @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate menu resource file. getMenuInflater().inflate(R.menu.share_menu, menu); // Locate MenuItem with ShareActionProvider MenuItem item = menu.findItem(R.id.menu_item_share); // Fetch and store ShareActionProvider mShareActionProvider = (ShareActionProvider) item.getActionProvider(); // Return true to display menu return true; } // Call to update the share intent private void setShareIntent(Intent shareIntent) { if (mShareActionProvider != null) { mShareActionProvider.setShareIntent(shareIntent); } }
0 comments:
Post a Comment