Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 776
deepthi Avatar asked Feb 10 '10 11:02

deepthi


People also ask

How do I open a website when a button is clicked Android?

You can wrap the buttons in anchors that href to the appropriate website. When the user clicks the button (input) they are directed to the destination specified in the href property of the anchor.

How do I redirect a specific URL?

Add a new URL redirectClick the URL Redirects tab. In the upper right, click Add URL redirect. In the right panel, select the Standard or Flexible redirect type. A standard redirect is used to redirect one URL to another.


1 Answers

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

  }

}
like image 105
ziya Avatar answered Oct 12 '22 00:10

ziya