Exception: This is not supported, use MenuItemCompat.getActionProvider()

First, you cannot use android.widget.ShareActionProvider with the appcompat-v7 action bar backport (e.g., ActionBarActivity). Either use the appcompat-v7 version of ShareActionProvider, or move everything over to the native action bar.

Second, if you stick with appcompat-v7, then you cannot safely use getActionProvider(), as that method will not exist on API Level 10 and below. Replace menuItem.getActionProvider() with MenuItemCompat.getActionProvider(menuItem).

FWIW, here is a sample project that implements the appcompat-v7 edition of ShareActionProvider.

Leave a Comment