使用浏览器打开网址 [英] Open url with an browser

查看:284
本文介绍了使用浏览器打开网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式在浏览器中以编程方式打开一个网址:

I programmattically open an Url in a browser by:

private final String url = "https://www.google.com";

Uri uri = Uri.parse(url);
Intent intent = new Intent();
intent.setData(uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

通常,代码可以正常工作,它会在浏览器中打开Http地址.

Generally, the code works fine, it opens the Http address in a browser.

但是总会有一个系统弹出对话框,要求用户选择一个应用程序以首先完成操作:

But there is always a system pop up dialog ask user to select an app to complete the action first:

用户必须从弹出菜单中选择 Chrome ,然后打开页面.我不明白为什么google +应用程序是其中的选项.

User has to select Chrome from the pop up, after then, the page opens. I don't understand why the google+ app is among the options.

如何避免此系统对话框选择应用程序?我的意思是如何设置默认浏览器(Chrome)&我的代码可以在没有此系统对话框的情况下打开网址?

How could I avoid this system dialog for app selection ? I mean how can I set a default browser (Chrome) & my code could just open the url without this system dialog ?

推荐答案

使用

Intent intent= new Intent(Intent.ACTION_VIEW,Uri.parse(YOUR_URL));
startActivity(intent);

但是您仍然必须在支持该操作和数据的不同浏览器或活动之间进行选择.

But you will still have to choose between different browsers or rather activities that support this action and data.

这篇关于使用浏览器打开网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆