Only Four Options For ShareActionProvider With ActionBarSherlock
Asked Answered
T

2

7

I am trying to share plain text while using a Share Action Provider via ActionBarSherlock and there are only four options to share it with and no "See all..." option.

Why is that?

This is what it looks like:

and this is what I want it to look like:

Tensimeter answered 4/6, 2012 at 20:30 Comment(2)
ActionShareProvider lists all apps that can handle the type of intent you create for the provider. If you are only seeing 4 then those are the only specific apps that accept data of the intent type you created. Also why would you want a photo sharing (category or app, not sure) to be listed for plain text?Ministerial
I am trying to use the Share Action Provider as an option for users to share a link to download my app and I have apps like facebook and twitter and there are no options for those apps. The picture I have of what I want it to look like is another app I have downloaded and when I select "See all..." There are about 10 different apps where I can share to.Tensimeter
M
8

OK so regardless of ActionBarSherlock first test to see if your creating your intent correctly, ABS uses the same code as the generic chooser does so see if the app's you are looking for show up when you execute 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 of that app's that handle plain text will show up, if facebook, or whatever you are expecting is not there then those app's don't support the ACTION_SEND intent for the type you have registered (plain/text). (Facebook does, but more about that in a minute)

ABS has a sample for using the share action provider but it try's to send a photo, not a text message (status update) the setup you should be using is 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 intent that will be used to match app's and list them out 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 it 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 at it did in the small test stub I showed with the chooser above.

Now for the bad news. The Facebook app doesn't really work, it will bring up the users update page, but it won't fill in the text. This is an on again, off again breakage, but I tried it last night and it was failing. It's a reported and accepted bug with the facebook app. You can post photo's though, although the caption can't be set see How many times will Facebook break/fix this?

Ministerial answered 15/6, 2012 at 0:56 Comment(0)
V
3

Just a note to future readers that ActionBarSherlock's ShareActionProvider does not support the overflow menu as of v4.1.0. Perhaps this might be updated in the future.


Here is the code from the share_action_provider.xml file 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 for information - it took me quite some time to find this out, so I want to make it easier for future readers to find.

Vair answered 11/12, 2012 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.