我正在尝试使用 intent 在浏览器中打开 URL。
我的代码是
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.onair99.com"));
startActivity(i);
这将导致在我尝试过的任何浏览器上出现错误,因为浏览器会尝试打开如下内容:
http://http//onair99.com//
据我所试,我只遇到过这个特定 URL 的问题。
有人知道为什么吗?
谢谢。
最佳答案
按照本 post 中所述进行操作
String url = "http://www.somewebsite.com";
在生产级代码中,您可能想检查 url 是否以 http 或 https 开头...最好检查一下
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
关于android - Intent 打开 url 导致浏览器上的 url 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25439943/