Only four options for ShareActionProvider with ActionBarSherlock

I am trying to use plain text when using an Action Action Provider through an ActionBarSherlock, and there are only four options for sharing it without the "View All ..." option.

Why is this?

Here's what it looks like:

and this is what I want it to look like this:

+7
source share
2 answers

OK, therefore, regardless of the first ActionBarSherlock test, to make sure you created your intent correctly, ABS uses the same code as the general selector, so see if the application you are looking for appears when you run this code.

Intent I= new Intent(Intent.ACTION_SEND); I.setType("text/plain"); I.putExtra(android.content.Intent.EXTRA_TEXT, "My Test Text"); startActivity(Intent.createChooser(I,"Share using ...")); 

All this application that processes plain text will be displayed, if facebook or what you expect does not exist, then this application does not support the ACTION_SEND intent for the type you registered (plain / text). (Facebook does, but more about that in a minute)

The ABS has a pattern for using a stock provider, but it is trying to send a photo, not a text message (status update) that you should use - it's something like this

 @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate your menu. getSupportMenuInflater().inflate(R.menu.share_action_provider, menu); // Set file with share history to the provider and set the share intent. MenuItem item = menu.findItem(R.id.menu_item_share_action_provider_action_bar); ShareActionProvider provider = (ShareActionProvider) item.getActionProvider(); provider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME); // Note that you can set/change the intent any time, // say when the user has selected an image. provider.setShareIntent(createShareIntent()); return true } 

And here is the intention that will be used to map the application and list it from the sample

 private Intent createShareIntent() { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/plain"); Uri uri = Uri.fromFile(getFileStreamPath("shared.png")); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.putExtra(Intent.EXTRA_TITLE, "This is an android icon"); return shareIntent; } 

but you want him to be

 private Intent createShareIntent() { Intent I= new Intent(Intent.ACTION_SEND); I.setType("text/plain"); I.putExtra(android.content.Intent.EXTRA_SUBJECT, "TEST - Disregard"); I.putExtra(android.content.Intent.EXTRA_TEXT, Uri.parse("http://noplace.com")); } 

This should give you the same list in ABS as in the little test stub I showed with the selection above.

Now about the bad news. The Facebook application does not really work, it will open the user update page, but the text will not be filled. It's turned on again, broken again, but I tried it last night and it failed. This is a reported and accepted error with the facebook application. You can post photos, although although the signature cannot be set, see How many times will Facebook break / fix it?

+8
source

Just notice to future readers that the ActionBarSherlock ShareActionProvider does not support the overflow menu since version 4.1. Perhaps this may be updated in the future.


Here is the code from share_action_provider.xml from the SampleList demo:

 <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_item_share_action_provider_action_bar" android:showAsAction="always" android:title="@string/action_bar_share_with" android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" /> <!-- XXX: For now, ShareActionProviders must be displayed on the action bar --> <!--item android:id="@+id/menu_item_share_action_provider_overflow" android:showAsAction="never" android:title="@string/action_bar_share_with" android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" /--> </menu> 

This answer is for information - it took me a while to figure this out, so I want its readers to be easier to find.

+3
source

All Articles