开发者

Android: Goto HTTP Url on Button Click

开发者 https://www.devze.com 2022-12-28 20:34 出处:网络
I want to go to a web page on t开发者_运维知识库he 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 t

I want to go to a web page on t开发者_运维知识库he 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?


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.


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

精彩评论

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