By Arutha


2010-02-04 17:51:45 8 Comments

How to open an URL from code in the built-in web browser rather than within my application?

I tried this:

try {
    Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(download_link));
    startActivity(myIntent);
} catch (ActivityNotFoundException e) {
    Toast.makeText(this, "No application can handle this request."
        + " Please install a webbrowser",  Toast.LENGTH_LONG).show();
    e.printStackTrace();
}

but I got an Exception:

No activity found to handle Intent{action=android.intent.action.VIEW data =www.google.com

30 comments

@Gaurav Lambole 2019-04-02 12:55:55

Simply go with short one to open your Url in Browser:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("YourUrlHere"));
startActivity(browserIntent);

@adadion 2019-04-05 08:05:17

What the difference with accepted answer?

@Umasankar 2019-03-11 07:34:16

Simple and Best Practice

Method 1:

String intentUrl="www.google.com";
Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentUrl));
    if(webIntent.resolveActivity(getPackageManager())!=null){
        startActivity(webIntent);    
    }else{
      /*show Error Toast 
              or 
        Open play store to download browser*/
            }

Method 2:

try{
    String intentUrl="www.google.com";
    Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentUrl));
        startActivity(webIntent);
    }catch (ActivityNotFoundException e){
                /*show Error Toast
                        or
                  Open play store to download browser*/
    }

@android developer 2014-04-08 09:19:51

Just like the solutions other have written (that work fine), I would like to answer the same thing, but with a tip that I think most would prefer to use.

In case you wish the app you start to open in a new task, indepandant of your own, instead of staying on the same stack, you can use this code:

final Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET|Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
startActivity(intent);

There is also a way to open the URL in Chrome Custom Tabs . Example in Kotlin :

@JvmStatic
fun openWebsite(activity: Activity, websiteUrl: String, useWebBrowserAppAsFallbackIfPossible: Boolean) {
    var websiteUrl = websiteUrl
    if (TextUtils.isEmpty(websiteUrl))
        return
    if (websiteUrl.startsWith("www"))
        websiteUrl = "http://$websiteUrl"
    else if (!websiteUrl.startsWith("http"))
        websiteUrl = "http://www.$websiteUrl"
    val finalWebsiteUrl = websiteUrl
    //https://github.com/GoogleChrome/custom-tabs-client
    val webviewFallback = object : CustomTabActivityHelper.CustomTabFallback {
        override fun openUri(activity: Activity, uri: Uri?) {
            var intent: Intent
            if (useWebBrowserAppAsFallbackIfPossible) {
                intent = Intent(Intent.ACTION_VIEW, Uri.parse(finalWebsiteUrl))
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_HISTORY
                        or Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
                if (!CollectionUtil.isEmpty(activity.packageManager.queryIntentActivities(intent, 0))) {
                    activity.startActivity(intent)
                    return
                }
            }
            // open our own Activity to show the URL
            intent = Intent(activity, WebViewActivity::class.java)
            WebViewActivity.prepareIntent(intent, finalWebsiteUrl)
            activity.startActivity(intent)
        }
    }
    val uri = Uri.parse(finalWebsiteUrl)
    val intentBuilder = CustomTabsIntent.Builder()
    val customTabsIntent = intentBuilder.build()
    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_HISTORY
            or Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
    CustomTabActivityHelper.openCustomTab(activity, customTabsIntent, uri, webviewFallback)
}

@The Original Android 2015-08-14 00:47:39

Will making a new task protect the source app from bugs and crashing, in case the web browser have problems?

@android developer 2015-08-14 10:49:20

@TheOriginalAndroid I don't understand what it has to do with crashes and web browser. Please explain what you are trying to do.

@The Original Android 2015-08-14 17:27:33

Thanks for your response. Your post is interesting. What is the benefit of opening a new task especially for a web launch?

@android developer 2015-08-14 20:32:43

@TheOriginalAndroid Just so that the user will be able to switch back to your app, and then back again to the web browser. If you open recent-tasks screen, you will see 2 tasks here instead of one. Also, instead of seeing a web browser thumbnail in the single task (that belongs to your app's task), you will see 2 : one of your app, and another of the web browser. I think it's less confusing this way.

@Tuan Nguyen 2018-11-21 09:37:47

dataWebView.setWebViewClient(new VbLinksWebClient() {
     @Override
     public void onPageFinished(WebView webView, String url) {
           super.onPageFinished(webView, url);
     }
});




public class VbLinksWebClient extends WebViewClient
{
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.trim())));
        return true;
    }
}

@ballu 2016-07-29 02:07:14

Basic Introduction:

https:// is using that one into the "code" so that no one in between can read them. This keeps your information safe from hackers.

http:// is using just sharing purpose, it's not secured.

About Your Problem:
XML designing:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.sridhar.sharedpreferencesstackoverflow.MainActivity">
   <LinearLayout
       android:orientation="horizontal"
       android:background="#228b22"
       android:layout_weight="1"
       android:layout_width="match_parent"
       android:layout_height="0dp">
      <Button
          android:id="@+id/normal_search"
          android:text="secure Search"
          android:onClick="secure"
          android:layout_weight="1"
          android:layout_width="0dp"
          android:layout_height="wrap_content" />
      <Button
          android:id="@+id/secure_search"
          android:text="Normal Search"
          android:onClick="normal"
          android:layout_weight="1"
          android:layout_width="0dp"
          android:layout_height="wrap_content" />
   </LinearLayout>

   <LinearLayout
       android:layout_weight="9"
       android:id="@+id/button_container"
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:orientation="horizontal">

      <WebView
          android:id="@+id/webView1"
          android:layout_width="match_parent"
          android:layout_height="match_parent" />

   </LinearLayout>
</LinearLayout>

Activity Designing:

public class MainActivity extends Activity {
    //securely open the browser
    public String Url_secure="https://www.stackoverflow.com";
    //normal purpouse
    public String Url_normal="https://www.stackoverflow.com";

    WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webView=(WebView)findViewById(R.id.webView1);

    }
    public void secure(View view){
        webView.setWebViewClient(new SecureSearch());
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webView.loadUrl(Url_secure);
    }
    public void normal(View view){
        webView.setWebViewClient(new NormalSearch());
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webView.loadUrl(Url_normal);

    }
    public class SecureSearch extends WebViewClient{
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String Url_secure) {
            view.loadUrl(Url_secure);
            return true;
        }
    }
    public class NormalSearch extends WebViewClient{
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String Url_normal) {
            view.loadUrl(Url_normal);
            return true;
        }
    }
}

Android Manifest.Xml permissions:

<uses-permission android:name="android.permission.INTERNET"/>

You face Problems when implementing this:

  1. getting The Manifest permissions
  2. excess space's between url
  3. Check your url's correct or not

@stacktry 2014-11-08 09:34:49

Simple, website view via intent,

Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.yoursite.in"));
startActivity(viewIntent);  

use this simple code toview your website in android app.

Add internet permission in manifest file,

<uses-permission android:name="android.permission.INTERNET" /> 

@francisco_ssb 2016-08-19 13:01:06

Chrome custom tabs are now available:

The first step is adding the Custom Tabs Support Library to your build.gradle file:

dependencies {
    ...
    compile 'com.android.support:customtabs:24.2.0'
}

And then, to open a chrome custom tab:

String url = "https://www.google.pt/";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));

For more info: https://developer.chrome.com/multidevice/android/customtabs

@Sanket 2012-06-25 08:01:43

other option In Load Url in Same Application using Webview

webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");

@Keelan 2013-06-10 20:30:19

Note that plugins and such are disabled in WebView, and that the INTERNET permissions would be required. (reference)

@nikki 2012-08-31 10:10:25

Try this:

Uri uri = Uri.parse("https://www.google.com");
startActivity(new Intent(Intent.ACTION_VIEW, uri));

or if you want then web browser open in your activity then do like this:

WebView webView = (WebView) findViewById(R.id.webView1);
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
webView.loadUrl(URL);

and if you want to use zoom control in your browser then you can use:

settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);

@Keelan 2013-06-10 20:30:44

Note that plugins and such are disabled in WebView, and that the INTERNET permissions would be required. (reference)

@Mark B 2010-02-04 18:01:42

Try this:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);

That works fine for me.

As for the missing "http://" I'd just do something like this:

if (!url.startsWith("http://") && !url.startsWith("https://"))
   url = "http://" + url;

I would also probably pre-populate your EditText that the user is typing a URL in with "http://".

@CommonsWare 2010-02-04 18:31:13

Except that your code and mbaird's aren't the same, from what I can tell for what's posted. Ensure that your URL has the http:// scheme -- the exception shown suggests that your URL is lacking the scheme.

@Arutha 2010-02-04 18:44:33

Yes ! It missed the http:// ! The URL is entered by the user, is there a way to automatically format?

@Mark B 2010-02-04 19:03:26

See the update to my answer above regarding detecting the missing http://

@Cameron McBride 2010-02-05 05:22:35

Tried this Intent and it works great!

@Techboy 2010-07-01 21:47:50

It needed another ')' after '("google.com")', but other than that it worked. Thanks :-)

@Dan 2011-06-21 19:30:55

URLUtil is a great way to check on user entered "url" Strings

@Kostadin 2012-01-12 13:49:07

When use Linkfy it is not nessesary to normalize url. Does anybody know proccess of transformation in Linkfy?

@tuxSlayer 2013-04-19 14:22:34

if (!url.startsWith("http://") && !url.startsWith("https://")) is a common error which may lead you to urls like file:// and break some good usecases. Try to parse uri with URI class and check is there a schema. If no, add "http://" ;)

@Chaitu 2013-09-06 04:51:02

Encode the Query String If any special characters or spaces. then It will work awesome.For Example : String query="For martin Luther King"; query=URLEncoder.encode(query); String url="en.wikipedia.org/wiki/Special:Search?search="+query; Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent);

@user1324936 2013-11-17 21:24:43

great answer. i splecial like if (!url.startsWith("http://") && !url.startsWith("https://")) url = "http://" + url;

@Torsten Ojaperv 2014-10-16 08:50:35

What about if(!url.contains("://") ? This wouldn't break file:// and others

@To Kra 2015-03-06 14:46:08

User Apache UrlValidator for such operations: UrlValidator.getInstance().isValid(url)

@itiskj 2015-08-24 05:09:56

You need null check with resolveCheck. See the offical docs : Caution: If there are no apps on the device that can receive the implicit intent, your app will crash when it calls startActivity(). To first verify that an app exists to receive the intent, call resolveActivity() on your Intent object.

@Mark B 2016-05-21 13:14:21

@MarthaJames If there is a better way to accomplish this now please post it as an answer.

@Iman Marashi 2017-10-14 18:58:18

com.android.chrome E/chromium: [ERROR:layer_tree_host_impl.cc(2206)] Forcing zero-copy tile initialization as worker context is missing

@Сергей Грушин 2018-05-26 12:02:32

how i can use it without deep links variants on my app?

@T. Roman 2018-01-23 14:07:21

Try this one OmegaIntentBuilder

OmegaIntentBuilder.from(context)
                .web("Your url here")
                .createIntentHandler()
                .failToast("You don't have app for open urls")
                .startActivity();

@Faakhir 2018-01-22 09:17:51

//OnClick Listener

  @Override
      public void onClick(View v) {
        String webUrl = news.getNewsURL();
        if(webUrl!="")
        Utils.intentWebURL(mContext, webUrl);
      }

//Your Util Method

public static void intentWebURL(Context context, String url) {
        if (!url.startsWith("http://") && !url.startsWith("https://")) {
            url = "http://" + url;
        }
        boolean flag = isURL(url);
        if (flag) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(url));
            context.startActivity(browserIntent);
        }

    }

@Cabuxa.Mapache 2018-04-20 05:47:08

Where is "isURL" defined?

@Vaibhav Kadam 2018-01-10 03:03:30

Okay,I checked every answer but what app has deeplinking with same URL that user want to use?

Today I got this case and answer is browserIntent.setPackage("browser_package_name");

e.g. :

   Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
    browserIntent.setPackage("com.android.chrome"); // Whatever browser you are using
    startActivity(browserIntent);

Thank you!

@Juan Carlos Velez 2017-07-11 13:02:53

The response of MarkB is right. In my case I'm using Xamarin, and the code to use with C# and Xamarin is:

var uri = Android.Net.Uri.Parse ("http://www.xamarin.com");
var intent = new Intent (Intent.ActionView, uri);
StartActivity (intent);

This information is taked from: https://developer.xamarin.com/recipes/android/fundamentals/intent/open_a_webpage_in_the_browser_application/

@I.G. Pascual 2017-06-21 10:57:50

android.webkit.URLUtil has the method guessUrl(String) working perfectly fine (even with file:// or data://) since Api level 1 (Android 1.0). Use as:

String url = URLUtil.guessUrl(link);

// url.com            ->  http://url.com/     (adds http://)
// http://url         ->  http://url.com/     (adds .com)
// https://url        ->  https://url.com/    (adds .com)
// url                ->  http://www.url.com/ (adds http://www. and .com)
// http://www.url.com ->  http://www.url.com/ 
// https://url.com    ->  https://url.com/
// file://dir/to/file ->  file://dir/to/file
// data://dataline    ->  data://dataline
// content://test     ->  content://test

In the Activity call:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URLUtil.guessUrl(download_link)));

if (intent.resolveActivity(getPackageManager()) != null)
    startActivity(intent);

Check the complete guessUrl code for more info.

@Zoe 2017-05-01 18:47:23

This way uses a method, to allow you to input any String instead of having a fixed input. This does save some lines of code if used a repeated amount of times, as you only need three lines to call the method.

public Intent getWebIntent(String url) {
    //Make sure it is a valid URL before parsing the URL.
    if(!url.contains("http://") && !url.contains("https://")){
        //If it isn't, just add the HTTP protocol at the start of the URL.
        url = "http://" + url;
    }
    //create the intent
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)/*And parse the valid URL. It doesn't need to be changed at this point, it we don't create an instance for it*/);
    if (intent.resolveActivity(getPackageManager()) != null) {
        //Make sure there is an app to handle this intent
        return intent;
    }
    //If there is no app, return null.
    return null;
}

Using this method makes it universally usable. IT doesn't have to be placed in a specific activity, as you can use it like this:

Intent i = getWebIntent("google.com");
if(i != null)
    startActivity();

Or if you want to start it outside an activity, you simply call startActivity on the activity instance:

Intent i = getWebIntent("google.com");
if(i != null)
    activityInstance.startActivity(i);

As seen in both of these code blocks there is a null-check. This is as it returns null if there is no app to handle the intent.

This method defaults to HTTP if there is no protocol defined, as there are websites who don't have an SSL certificate(what you need for an HTTPS connection) and those will stop working if you attempt to use HTTPS and it isn't there. Any website can still force over to HTTPS, so those sides lands you at HTTPS either way


Because this method uses outside resources to display the page, there is no need for you to declare the INternet permission. The app that displays the webpage has to do that

@Debasish Ghosh 2017-03-30 11:35:26

Try this..Worked for me!

    public void webLaunch(View view) {
            WebView myWebView = (WebView) findViewById(R.id.webview);
            myWebView.setVisibility(View.VISIBLE);
            View view1=findViewById(R.id.recharge);
            view1.setVisibility(View.GONE);
            myWebView.getSettings().setJavaScriptEnabled(true);
            myWebView.loadUrl("<your link>");

        }

xml code :-

 <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:visibility="gone"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />

--------- OR------------------

String url = "";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

@Zoe 2017-05-01 18:48:00

For most apps, adding a WebView is a hard way of doing it. It is easier opening the URL in the browser.

@Zoe 2017-05-04 17:30:40

I didn't downvote.

@Salam El-Banna 2017-01-19 07:58:13

If you want to do this with XML not programmatically you can use on your TextView:

android:autoLink="web"
android:linksClickable="true"

@divonas 2016-12-16 06:35:33

Based on the answer by Mark B and the comments bellow:

protected void launchUrl(String url) {
    Uri uri = Uri.parse(url);

    if (uri.getScheme() == null || uri.getScheme().isEmpty()) {
        uri = Uri.parse("http://" + url);
    }

    Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);

    if (browserIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(browserIntent);
    }
}

@Karthik Sridharan 2016-10-05 06:30:59

I think this is the best

openBrowser(context, "http://www.google.com")

Put below code into global class

    public static void openBrowser(Context context, String url) {

        if (!url.startsWith("http://") && !url.startsWith("https://"))
            url = "http://" + url;

        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        context.startActivity(browserIntent);
    }

@Karthik Sridharan 2016-10-05 06:31:15

no permission needed

@Dmytro Danylyk 2013-01-09 08:55:14

If you want to show user a dialogue with all browser list, so he can choose preferred, here is sample code:

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

public static void openBrowser(final Context context, String url) {

     if (!url.startsWith(HTTP) && !url.startsWith(HTTPS)) {
            url = HTTP + url;
     }

     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
     context.startActivity(Intent.createChooser(intent, "Choose browser"));// Choose browser is arbitrary :)

}

@Jeffrey Blattman 2013-04-18 19:22:40

if there are multiple apps that can handle the intent, the system will automatically provide a chooser, right?

@xmen 2014-12-26 04:40:51

whats the point of making HTTP and HTTPS fields ?

@Dmytro Danylyk 2014-12-26 07:19:51

@xmen-w-k because url can start ether with http or https, and in java it is a good practice to declare 'magic strings' as constants.

@Erdal G. 2016-02-26 17:26:47

@JeffreyBlattman yes (2 years later ^^)

@WuerfelDev 2016-08-15 17:14:43

thx, didn't know about context.startActivity. Very useful when calling it from an external class

@itiskj 2015-08-24 05:06:00

Simple Answer

You can see the official sample from Android Developer.

/**
 * Open a web page of a specified URL
 *
 * @param url URL to open
 */
public void openWebPage(String url) {
    Uri webpage = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

How it works

Please have a look at the constructor of Intent:

public Intent (String action, Uri uri)

You can pass android.net.Uri instance to the 2nd parameter, and a new Intent is created based on the given data url.

And then, simply call startActivity(Intent intent) to start a new Activity, which is bundled with the Intent with the given URL.

Do I need the if check statement?

Yes. The docs says:

If there are no apps on the device that can receive the implicit intent, your app will crash when it calls startActivity(). To first verify that an app exists to receive the intent, call resolveActivity() on your Intent object. If the result is non-null, there is at least one app that can handle the intent and it's safe to call startActivity(). If the result is null, you should not use the intent and, if possible, you should disable the feature that invokes the intent.

Bonus

You can write in one line when creating the Intent instance like below:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

@IgorGanapolsky 2017-05-15 18:06:16

This presumes that the supplied url has http in it.

@Sonia John Kavery 2015-10-12 10:46:13

Check whether your url is correct. For me there was an unwanted space before url.

@Gorav Sharma 2015-11-12 21:41:16

Webview can be used to load Url in your applicaion. URL can be provided from user in text view or you can hardcode it.

Also don't forget internet permissions in AndroidManifest.

String url="http://developer.android.com/index.html"

WebView wv=(WebView)findViewById(R.id.webView);
wv.setWebViewClient(new MyBrowser());
wv.getSettings().setLoadsImagesAutomatically(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv.loadUrl(url);

private class MyBrowser extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

@CrandellWS 2016-02-15 06:36:18

@Elenasys 2014-05-27 14:20:57

a common way to achieve this is with the next code:

String url = "http://www.stackoverflow.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url)); 
startActivity(i); 

that could be changed to a short code version ...

Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.stackoverflow.com"));      
startActivity(intent); 

or :

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com")); 
startActivity(intent);

the shortest! :

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com")));

happy coding!

@Kanwar_Singh 2014-01-09 12:37:03

Within in your try block,paste the following code,Android Intent uses directly the link within the URI(Uniform Resource Identifier) braces in order to identify the location of your link.

You can try this:

Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(myIntent);

@Pradeep Sodhi 2014-09-04 07:19:37

String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

@TheOddAbhi 2014-07-17 12:40:53

Intent getWebPage = new Intent(Intent.ACTION_VIEW, Uri.parse(MyLink));          
startActivity(getWebPage);

@tony gil 2014-07-17 13:30:17

welcome, newbie. please make the answer more complete, declaring variables that do not exist in original code.

@Aristo Michael 2013-12-19 06:04:08

You can also go this way

In xml :

<?xml version="1.0" encoding="utf-8"?>
<WebView  
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

In java code :

public class WebViewActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("http://www.google.com");

 }

}

In Manifest dont forget to add internet permission...

@The Original Android 2015-08-14 00:45:09

This is interesting and different. I guess this way the user sees a web browser in my app. Is that right? I upvote.

@Elenasys 2013-12-03 16:24:32

A short code version...

 if (!strUrl.startsWith("http://") && !strUrl.startsWith("https://")){
     strUrl= "http://" + strUrl;
 }


 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(strUrl)));

Related Questions

Sponsored Content

52 Answered Questions

53 Answered Questions

[SOLVED] How to get the value from the GET parameters?

  • 2009-06-11 08:32:49
  • joe
  • 1817567 View
  • 1138 Score
  • 53 Answer
  • Tags:   javascript url

15 Answered Questions

[SOLVED] How to change the URI (URL) for a remote Git repository?

  • 2010-03-12 12:48:47
  • e-satis
  • 1279774 View
  • 3239 Score
  • 15 Answer
  • Tags:   git url git-remote

77 Answered Questions

73 Answered Questions

[SOLVED] How can I get query string values in JavaScript?

16 Answered Questions

[SOLVED] What is the maximum length of a URL in different browsers?

  • 2009-01-06 16:14:30
  • Sander Versluys
  • 1128578 View
  • 4503 Score
  • 16 Answer
  • Tags:   http url browser

18 Answered Questions

[SOLVED] How do I modify the URL without reloading the page?

20 Answered Questions

[SOLVED] How to open the Google Play Store directly from my Android application?

33 Answered Questions

[SOLVED] How do I get the current absolute URL in Ruby on Rails?

10 Answered Questions

[SOLVED] Sending an Intent to browser to open specific URL

Sponsored Content