Implicit intent to view url

I am new to Android, I want to create an intent to view google website. My string is declared as follows:

static private final String URL = "http://www.google.com";

and my intention:

Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("geo:+URL"));
startActivity(browserIntent);

This code does not show errors in Eclipse, but I think it might be wrong.

+3
source share
5 answers

You are not building your Uri correctly, trying to combine 2 lines, use this:

String s = "I'm a string variable";

String concatenated = s + " and I'm another String variable";

Now the contents of concatenated

I am a string variable and I am another String variable

If you do this:

String concatenated = "s + and I'm another String variable";

concatenated content

s + and I am another String variable

Secondly, why do you use geo-uri? This is for viewing locations. To view a website, simply use the URL (and don't forget the “http: //” part):

String URL = "http://www.google.com";
browserIntent.setData(Uri.parse(URL));
+5

, . Intent , String URI .

geo:, - . URL- , URL- -. Uri.parse(), URI, intents. -

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
Intent browserChooserIntent = Intent.createChooser(browserIntent , "Choose browser of your choice");
startActivity(browserChooserIntent );
+2

https://www.youtube.com/watch?v=lkadcYQ6SuY&hd=1 , , 94, . , 2Dee . , , , String, Android. .

0
source

2Dee's answer is correct. You can also give an action and set uri data in one line. To view the website.

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
startActivity(browserIntent);
0
source
 Intent browserIntent=null, chooser=null;
    browserIntent= new Intent(Intent.ACTION_VIEW);
    browserIntent.setData(Uri.parse("http://www.google.com"));
    chooser = browserIntent.createChooser(intent,"Open Website Using...");
    if(browserIntent.resolveActivity(getPackageManager()) != null){
        startActivity(chooser);
    }
0
source

All Articles