Android:单击按钮时转到 HTTP Url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2762861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: Goto HTTP Url on Button Click
提问by Chris
I want to go to a web page on the click of a button in my Android app. So say, I have a button called "Google", when the user clicks on that button I want google.com to open up on the screen. How is this achieved?
我想通过点击我的 Android 应用程序中的一个按钮来访问一个网页。比如说,我有一个名为“Google”的按钮,当用户单击该按钮时,我希望 google.com 在屏幕上打开。这是如何实现的?
Also, is there a way I can gain control back to my app once the user is finished with Google?
另外,有没有办法在用户使用完 Google 后重新获得对我的应用程序的控制权?
回答by drawnonward
In your activity do something like this.
在你的活动中做这样的事情。
public void openWebURL( String inURL ) {
Intent browse = new Intent( Intent.ACTION_VIEW , Uri.parse( inURL ) );
startActivity( browse );
}
By default, quitting the browser should return to your activity. However, there may be situations where it will not.
默认情况下,退出浏览器应返回到您的活动。但是,可能存在不会的情况。
回答by Furkan Uzun?akmak
This code will take you to the web page
此代码将带您到网页
public void goToWebPage(String yourUrl)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(yourUrl));
startActivity(intent);
}