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 Intent :
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("geo:+URL"));
startActivity(browserIntent);
This code shows no errors in Eclipse, but I think it might be wrong.
You're not building your Uri correctly, when trying to concatenate 2 String, use this :
String s = "I'm a string variable";
String concatenated = s + " and I'm another String variable";
Now the content of concatenated is
I'm a string variable and I'm another String variable
If you do this :
String concatenated = "s + and I'm another String variable";
the content of concatenated is
s + and I'm another String variable
Secondly, why are you using a geo Uri ? This is for viewing locations. To view a website, just use the URL (and don't forget the "http://" part) :
String URL = "http://www.google.com";
browserIntent.setData(Uri.parse(URL));
You can create an intent and then set data for it. Intent also has a constructor that takes action String and data URI.
Also you need to use geo:
when you want to show something on a map. So view an URL in browser you can simply use the website URL. You can pass it to Uri.parse()
method to get URI object needed in the intents constructor.
You can simply do -
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 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With