Android – how to open a button click URL in the default browser or WebView

How do I open a web address in WebView or the default browser after clicking the button? At present, when I click the BTN1 button, it will prompt me to select a browser from my phone. I want to open this URL in the default browser or WebView

This is my java code:

 public class myactivity extends Activity {

@Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button bt1 = (Button) findViewById(R.id.btn_click_login);
    btn_login.setOnClickListener(new OnClickListener() {
         public void onClick(View v) {
             Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
             myWebLink.setData(Uri.parse("http://google.com"));
             startActivity(myWebLink);
          }
         }
     );
}

resolvent:

good job.

Make sure that < uses permission Android: name = "Android. Permission. Internet" / > is included in the list

Intent internetIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"));
internetIntent.setComponent(new ComponentName("com.android.browser","com.android.browser.BrowserActivity"));
internetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(internetIntent);

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>