ActionBar share item produces “Android System” thi

2019-02-18 14:32发布

I want a share icon in the action bar, upon pressing, a chooser shows up. I have most of this in place, but this unwelcome middle-man steps in...

The menu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_share"
          android:title="@string/share"
          android:showAsAction="always"
          android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider"
    />    
</menu>

The SherlockFragment's onCreateOptionsMenu:

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {     
    // Inflate menu resource file.
    inflater.inflate(R.menu.share_menu, menu);

    // Locate MenuItem with ShareActionProvider
    MenuItem item = menu.findItem(R.id.menu_share);

    // Fetch and store ShareActionProvider
    this.shareActionProvider = (ShareActionProvider) item.getActionProvider();

    final String title = r.getString(R.string.feedback_share);
    final String subject = r.getString(R.string.share_subject);
    final String message = r.getString(R.string.share_message_plain);

    Intent intent = app.newShareIntent(title, subject, message);
    this.shareActionProvider.setShareIntent(intent);
}

The intent factory:

public Intent newShareIntent(String title, String subject, String message) {            
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, message);

    Intent chooser = Intent.createChooser(intent, title);
    chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    return chooser;
}

The unwelcome middle-man:

enter image description here

And when I click on this guy, he does as directed and presents the chooser. But I'm really not interested in engaging his services.

What I'm after:

enter image description here

Or this with all three (or however many on users devices) in the drop down... or be able to set the default that appears inline with the share icon:

enter image description here

1条回答
劫难
2楼-- · 2019-02-18 15:24

But I'm really not interested in engaging his services.

But you asked for "his services", as you're the one who called createChooser() and decided to use that as your share Intent.

Get rid of that, returning your ACTION_SEND Intent directly, and "Android System" should go away.

查看更多
登录 后发表回答