See the picture. How can i hide the icon "P" which means share to Pinterest?
They are both on the action bar and I use ActionBarSherlock.
If you wish to keep all the share history data model, but just don't want the extra "default share activity" icom. The answer at How do you turn off share history when using ShareActionProvider? is not good enough.
What you should do is:
if (activityCount > 0 && historySize > 0)
if (false)
(it's pretty ugly, but it's the quickest fix. you can delve into the code to remove all occurrences of DefaultActivity implementation)
Edit:
Don't forget to set the new ActionProvider
to your menu item, from XML it would look like: android:actionProviderClass="com.*.CustomShareActionProvider"
That's it!
I found a way to work around this. I am using support library 23.0.1, I have not tested this on other support library versions.
The solution is easy, when you create ShareActionProvider, just override method onCreateActionView() and return null for it. Then you can track all history in the popup menu, but the history will not be shown in toolbar.
Here is a code sample:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem item = menu.add(Menu.NONE, R.id.menu_share, Menu.NONE, R.string.share);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
mShareActionProvider = new ShareActionProvider(this) {
@Override
public View onCreateActionView() {
return null;
}
};
item.setIcon(R.drawable.abc_ic_menu_share_mtrl_alpha);
MenuItemCompat.setActionProvider(item, mShareActionProvider);
return true;
}
Currently I have not found any problem using this work around.
Based off Sean's answer I created the necessary classes, you can copy them into your project (https://gist.github.com/saulpower/10557956). This not only adds the ability to turn off history, but also to filter the apps you would like to share with (if you know the package name).
private final String[] INTENT_FILTER = new String[] {
"com.twitter.android",
"com.facebook.katana"
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.journal_entry_menu, menu);
// Set up ShareActionProvider's default share intent
MenuItem shareItem = menu.findItem(R.id.action_share);
if (shareItem instanceof SupportMenuItem) {
mShareActionProvider = new ShareActionProvider(this);
mShareActionProvider.setShareIntent(ShareUtils.share(mJournalEntry));
mShareActionProvider.setIntentFilter(Arrays.asList(INTENT_FILTER));
mShareActionProvider.setShowHistory(false);
((SupportMenuItem) shareItem).setSupportActionProvider(mShareActionProvider);
}
return super.onCreateOptionsMenu(menu);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With