2017-01-24 36 views
0

我正在使用全局共享意图共享一些文本如下;如何忽略用户使用全局共享设置的默认共享应用程序目的

Intent intent = new Intent(); 
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); 
     intent.setAction(Intent.ACTION_SEND); 
     intent.setType("text/plain"); 
     intent.putExtra(Intent.EXTRA_TEXT, "Some Text"); 
     startActivity(intent); 

的问题是我要显示所有可用的应用程序与即使用户设置的默认应用共享文本,如下图所示enter image description here

回答

0

有关使用ShareActionProvider

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <item 
     android:id="@+id/menu_item_share" 
     app:showAsAction="ifRoom" 
     android:title="Share" 
     app:actionProviderClass="android.support.v7.widget.ShareActionProvider" /> 
    ... 
</menu> 
如何

它不应该要求Just Once和“总是”选项。您可以在“菜单选项”中或任何您想要的位置添加此菜单。

0

有一种方法可以使用PackageManager来清除自己的缺陷活动,但无法清除其他活动。

因此,作为解决方法,您可以为此创建自己的用户界面。例如放在BottomSheet数据,你明白我的方式:

PackageManager manager = context.getPackageManager(); 
List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0); 
if (infos.size() > 0) { 
    //do UI stuff 
} else { 
    //No Application can handle your intent 
} 

它可以看起来像为:

enter image description here

相关问题