Android – how to view a list from the browser by clicking a button

I have an activity similar to the following code. When I click the button, I want to see a list from the browser. When I select one of them, I use the selected browser to access it https://www.google.com Website. I know I should use the intent method for this, but I don't know how to use this method in the manifest file and mainactivity.java file

public class MainActivity extends Activity {

Button button;
String url = "https://www.google.com";
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }}

resolvent:

You can do this in the button. Click here. The URL is your URL

private static final String HTTPS = "https://";
private static final String HTTP = "http://";

  button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
         // To check if url starts with http or https if not then will throw an exception
         if (!url.startsWith(HTTP) && !url.startsWith(HTTPS)) {
           url = HTTP + url;
         }
         Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
         startActivity(Intent.createChooser(intent, "Choose browser"));

      }
    });


}

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
分享
二维码
< <上一篇
下一篇>>