ActionBar 共享项生成“Android 系统"东西 [英] ActionBar share item produces "Android System" thingy
问题描述
我希望在操作栏中有一个共享图标,按下后会出现一个选择器.我已经准备好了大部分内容,但是这个不受欢迎的中间人介入了......
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...
菜单:
<?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>
SherlockFragment 的 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);
}
意图工厂:
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;
}
不受欢迎的中间人:
当我点击这个人时,他会按照指示执行并显示选择器.但我真的对使用他的服务不感兴趣.
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.
我的追求:
或者在下拉列表中使用所有三个(或用户设备上的多个)...或者能够设置与共享图标内联显示的默认值:
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:
推荐答案
但我真的对使用他的服务不感兴趣.
But I'm really not interested in engaging his services.
但是您要求他的服务",因为您是调用 createChooser()
并决定将其用作您的共享 Intent
的人.
But you asked for "his services", as you're the one who called createChooser()
and decided to use that as your share Intent
.
摆脱它,直接返回您的ACTION_SEND
Intent
,Android 系统"应该消失.
Get rid of that, returning your ACTION_SEND
Intent
directly, and "Android System" should go away.
这篇关于ActionBar 共享项生成“Android 系统"东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!