开发者

How to open default browser

开发者 https://www.devze.com 2023-01-12 12:25 出处:网络
I want to make somethink like hyperlink. Right now, i created button, which opens new Activity with WebView开发者_C百科. But i want to open a \"globally\" default web browser at specified url. How can

I want to make somethink like hyperlink. Right now, i created button, which opens new Activity with WebView开发者_C百科. But i want to open a "globally" default web browser at specified url. 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

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


Just make and Intent and set the link as uri to the intent. Then use the intent to start activity. Try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号