如何在内置的网页浏览器中从代码打开一个URL,而不是在我的应用程序中?
我尝试这样做:
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));
startActivity(myIntent);
但是我得到了一个异常:"No activity found to handle Intent{action=android.intent.action.VIEW data =www.google.com"
试试这个:
Intent browserIntent= new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));startActivity(browserIntent);
我用这个是可以的。
对于缺少的"http://" ,我通常是这样做:
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
我也可能将用户输入的带有"http://"的URL地址先填到你的EditText
在2.3中,我是这样做的,而且也成功了
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
activity.startActivity(intent);
区别就是使用了Intent.ACTION_VIEW,而不是"android.intent.action.VIEW"字符串。
http://blog.csdn.net/zlqqhs/article/details/8600690
多种常用Intent,有你要的答案,前面需要加协议http://
你的手机中没有可以打开网页的应用