发送意图到浏览器以打开特定的URL [重复]

本文翻译自:Sending an Intent to browser to open specific URL [duplicate]

This question already has an answer here: 这个问题已经在这里有了答案:

I'm just wondering how to fire up an Intent to the phone's browser to open an specific URL and display it. 我只是想知道如何在手机浏览器中启动一个Intent以打开特定的URL并显示它。

Can someone please give me a hint? 有人可以给我提示吗?


#1楼

参考:https://stackoom.com/question/Cbbv/发送意图到浏览器以打开特定的URL-重复


#2楼

In some cases URL may start with "www". 在某些情况下,URL可能以“ www”开头。 In this case you will get an exception: 在这种情况下,您将获得一个例外:

android.content.ActivityNotFoundException: No Activity found to handle Intent

The URL must always start with "http://" or "https://" so I use this snipped of code: 该URL必须始终以“ http://”或“ https://”开头,因此我使用以下代码段:

if (!url.startsWith("https://") && !url.startsWith("http://")){
    url = "http://" + url;
}
Intent openUrlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(openUrlIntent);

#3楼

最短的版本。

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")));

#4楼

From XML 从XML

In case if you have the web-address/URL displayed on your view and you want it to make it clikable and direct user to particular website You can use: 如果您的视图上显示了Web地址/ URL,并且希望它使用户更容易理解并直接将其定向到特定网站,则可以使用:

android:autoLink="web"

In same way you can use different attributes of autoLink(email, phone, map, all) to accomplish your task... 同样,您可以使用autoLink的不同属性(电子邮件,电话,地图等)来完成任务...


#5楼

Use following snippet in your code 在代码中使用以下代码段

Intent newIntent = new Intent(Intent.ACTION_VIEW, 
Uri.parse("https://www.google.co.in/?gws_rd=cr"));
startActivity(newIntent);

Use This link 使用此链接

http://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW http://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW


#6楼

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值