Android: Goto HTTP Url on Button Click

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 08:59:03

问题


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?

Also, is there a way I can gain control back to my app once the user is finished with Google?


回答1:


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.




回答2:


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);
}


来源:https://stackoverflow.com/questions/2762861/android-goto-http-url-on-button-click

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