简体   繁体   English

如何打开默认浏览器

[英]How to open default browser

I want to make somethink like hyperlink. 我想做一些像超链接的事情。 Right now, i created button, which opens new Activity with WebView. 现在,我创建了一个按钮,该按钮使用WebView打开新的Activity。 But i want to open a "globally" default web browser at specified url. 但我想在指定的URL打开“全局”默认Web浏览器。 How can i do this ? 我怎样才能做到这一点 ?

You can fire a global intent that will be picked up by the browser 您可以触发将由浏览器获取的全局意图

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

Also make sure to add the web permission to your manifest 还要确保将Web权限添加到清单中

<uses-permission android:name="android.permission.INTERNET" />

Just make and Intent and set the link as uri to the intent. 只需进行make和Intent并将链接设置为uri即可。 Then use the intent to start activity. 然后使用意图开始活动。 Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM