How do I launch a URL from my application on Android?

余生长醉 提交于 2019-12-19 03:37:16

问题


How can I code my Android application to start the web browser to display a given URL?

(I'd rather not embed a web browser component into my app, but rather want to start the Android web browser to show the URL.)

Thanks!


回答1:


Just use an Intent with the correct action and data:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);



回答2:


In case if you have the website displayed on your view and you want it to make it clikable and direct user to particular website You can use:

android:autoLink="web"

In same way you can use different attributes of autoLink(email, phone, map, all) to accomplish your task...



来源:https://stackoverflow.com/questions/2060949/how-do-i-launch-a-url-from-my-application-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!