how to redirect to particular URL while clicking on button in android?

后端 未结 1 760
旧巷少年郎
旧巷少年郎 2021-02-08 11:16

I want to redirect user to particular URL while clicking on Button in Android App.

1条回答
  •  遥遥无期
    2021-02-08 12:07

    You can start a 'view' activity, which would be the browser given a URL:

    public class HelloWorld extends Activity {
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        // Assuming you are using xml layout
        Button button = (Button)findViewById(R.id.Button01);
    
        button.setOnClickListener(new OnClickListener() {
          public void onClick(View arg0) {
            Intent viewIntent =
              new Intent("android.intent.action.VIEW",
                Uri.parse("http://www.stackoverflow.com/"));
              startActivity(viewIntent);
          }
        });
    
      }
    
    }
    

    0 讨论(0)
提交回复
热议问题