How to open a website when a Button is clicked in Android application?

how to make an android app that links to a website
open link on click of button android
android app redirect to website
onclicklistener android button
how to open google map on button click in android
open browser on button click
on button click open new page in android
open new layout on button click android

I am designing an app, with several button for users to click on. Once button is clicked, user is directed to appropriate website. How do I accomplish this?

If you are talking about an RCP app, then what you need is the SWT link widget.

Here is the official link event handler snippet.

Update

Here is minimalist android application to connect to either superuser or stackoverflow with 2 buttons.

package ap.android;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class LinkButtons extends Activity {

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

    public void goToSo (View view) {
        goToUrl ( "http://stackoverflow.com/");
    }

    public void goToSu (View view) {
        goToUrl ( "http://superuser.com/");
    }

    private void goToUrl (String url) {
        Uri uriUrl = Uri.parse(url);
        Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
        startActivity(launchBrowser);
    }

}

And here is the layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/select" />
    <Button android:layout_height="wrap_content" android:clickable="true" android:autoLink="web" android:cursorVisible="true" android:layout_width="match_parent" android:id="@+id/button_so" android:text="StackOverflow" android:linksClickable="true" android:onClick="goToSo"></Button>
    <Button android:layout_height="wrap_content" android:layout_width="match_parent" android:text="SuperUser" android:autoLink="web" android:clickable="true" android:id="@+id/button_su" android:onClick="goToSu"></Button>
</LinearLayout>

How to open any website by clicking a button in Android Studio , In this Android Tutorial, we shall look into an application, where we click a button, and a URL is opened in a browser window. Open URL from Android Application​  If you are talking about an RCP app, then what you need is the SWT link widget.. Here is the official link event handler snippet.. Update. Here is minimalist android application to connect to either superuser or stackoverflow with 2 buttons.

In your Java file write the following piece of code...

ImageView Button = (ImageView)findViewById(R.id.yourButtonsId);

Button.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setData(Uri.parse("http://www.yourURL.com"));
        startActivity(intent);
    }
});

Android Studio, Android application developer can insert an particular website URL into android activity on button click using Intent and when user clicks on  Android application developer can insert an particular website URL into android activity on button click using Intent and when user clicks on button then it will automatically open given url into built in default mobile device web browser. So here is the complete step by step tutorial for Open Website Url in Android’s Web browser from application.

Here is a workable answer.

Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.tutorial.todolist"
  android:versionCode="1"
  android:versionName="1.0">
  <uses-sdk android:minSdkVersion="3"></uses-sdk>
  <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".todolist"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  </application>
</manifest>
todolist.java
package com.tutorial.todolist;
import android.app.Activity; 
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; 
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

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

        Button btn = (Button) findViewById(R.id.btn_clickme);
        btn.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
                myWebLink.setData(Uri.parse("http://www.anddev.org"));
                    startActivity(myWebLink);
             }
        });
    }
}
main.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="schemas.android.com/apk/res/android"
  android:orientation="vertical" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" > 

    <Button android:id="@+id/btn_clickme" 
      android:text="Click me..." 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 
</LinearLayout>

Android App for open website by Clicking on Button using Android , This example demonstrates about how do I start new Activity on click button in Android. Mobile Development · Front End · Web Development · Selenium · MongoDB · Computer Network <Button android:id="@+id/button" android:​layout_width="wrap_content" <application android:allowBackup="true"  1. Open any website by typing the URl in the app. 2. Set a home page for our browser. 3. Open a locally saved webpage in our Android App. To build this Android APP, we will use a webview to display webpages. We will make an editText, in which user will enter URL and a button which on click would load the URL.

Import import android.net.Uri;

Intent openURL = new Intent(android.content.Intent.ACTION_VIEW);
openURL.setData(Uri.parse("http://www.example.com"));
startActivity(openURL);

or it can be done using,

TextView textView = (TextView)findViewById(R.id.yourID);

textView.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setData(Uri.parse("http://www.typeyourURL.com"));
        startActivity(intent);
    } });

[FREE SOURCE CODE] Open URL onclick certain button, Create a new project: "DemoActivity File" --> "New" --> "Android Application Project". new prjt.jpg. Step 2. Open "DemoActivity /res/values/string. Android - WebView - WebView is a view that display web pages inside your application. You can also specify HTML string and can show it inside your application using WebView.

ImageView Button = (ImageView)findViewById(R.id.button);

Button.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Uri uri = Uri.parse("http://google.com/");

        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }
});

Open URL from Android Application separately in Browser Activity, To define the click event handler for a button, add the android:onClick attribute to the <Button> element in your XML layout. The value for this  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Open Website Url in Android's Web browser from application , After the signing process completes, click Open Distribution: This causes Windows Explorer to open the folder containing the generated APK file. At this point, Visual Studio has compiled the Xamarin.Android application into an APK that is ready for distribution. The following screenshot displays an example of the ready-to-publish app, MyApp

How to start new Activity on click button in Android?, The app details will appear, Click on install button and it will take a moment hold on until installation completes. Now click on the open button to open Honeycode App.

How to Open New Activity on Click Button by Existing Activity In , Open New Activity from Android Button Click - Duration: 12:38. codesolutionz 293,472 views. 12:38. Android 2019 : Adding code to a Button Click in Android Studio - Duration: 11:03.

Comments
  • When you say "I am designing an app", do you mean an RCP app, or an eclipse app not based on RCP but based on the IDE itself ?
  • I am having troubles typing for some reason. Here is what I got so far: I added <uses-sdk android:minSdkVersion="3"></uses-sdk> <uses-permission android:name="android.permission.INTERNET" /> to the manifest. I added a button in layout, in the place where you can actually see the button. res> drawable >layout>main. Now what do I do? Thanks again!
  • I am talking about an Eclipse App. I honestly don't know what is it based on.I hope it's based on my future success. I just downloaded Eclipse, it's working for developing very simple apps like, when user opens my app, it immediately directs user to a website. But I want to give user a choice to pick from several buttons to go to appropriate website. For example, if you are hungry and want to pick a place to eat, choose McDonald's, Burger King , Subway . So I want him to click on one of those buttons and connect to appropriate website
  • I think, what you mean is: an android app based on the android sdk with the eclipse IDE. I'll add the android tag.
  • Yes, I didn't read that you are working with Eclipse. Ignore my answer.
  • Ok, thanks. I put your answer into Eclipse and it doesn't read it right
  • even if it's html. you cant just wrap the button with the anchor tag.