如何排除ACTION_VIEW意向特定应用程序? [英] How to exclude a specific application from ACTION_VIEW Intent?
问题描述
我试图加载在浏览器中的URL叽叽喳喳
I am trying to load a twitter URL in browser.
在我的手机,我已经安装了Twitter的应用程序也。我试图使用 ACTION_VIEW
意图打开URL。但是,是什么情况,当我打电话的意图,Android将显示默认的选择对话框,其中包含Twitter的应用程序也(如果它安装在设备上)。我想只能用浏览器打开URL。 我要排除从该对话框 Twitter应用程序。我想在设备中的所有availaible浏览器在像Twitter对话,而不是本机应用程序展现出来,脸谱等。
In my phone, I have already installed twitter app also. I am trying to open URL using ACTION_VIEW
intent. But what happens is, when I call intent, android will show default chooser dialog, which contains twitter app also (if it is installed on device). I want to open the URL using browsers only. I want to exclude Twitter application from the dialog. I want all availaible browsers in device to show up in dialog, not native applications like twitter, facebook etc.
时,可以不?如果可能的话任何人都可以帮助我实现它。我还附上我的code和这个问题的清晰度以及屏幕截图。
Is it is possible or not? If possible could anyone help me in achieving it. I am also attaching my code and a screenshot along with this question for clarity.
String url = "https://twitter.com";
MimeTypeMap map = MimeTypeMap.getSingleton();
String type = map.getMimeTypeFromExtension(url);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setType(type);
i.setData(Uri.parse(url));
startActivity(i);
推荐答案
您只需要目标包设置为意图:
You just need to set the target package to the intent:
String url = "https://twitter.com";
MimeTypeMap map = MimeTypeMap.getSingleton();
String type = map.getMimeTypeFromExtension(url);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setType(type);
i.setData(Uri.parse(url));
ComponentName comp = new ComponentName("com.android.browser", "com.android.browser.BrowserActivity");
i.setComponent(comp);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
不过,用户可我如果他们有一些安装自定义浏览器,并希望以此作为默认的不安。
However, users my be disturbed if they have some custom browser installed and want to use this as default.
您可以尝试用检测默认浏览器:
You can try to detect the default browser with:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com"));
List<ResolveInfo> list = context.getPackageManager()
.queryIntentActivities(i, 0);
// walk through list and select your most favorite browser
这篇关于如何排除ACTION_VIEW意向特定应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!