Michael
Michael

Reputation: 524

Open browser at specified URL using ACTION_VIEW not working when chrome is default browser

I have 2 browsers installed on my Android device 1) default and 2) Chrome

When I run the following code I get a 'Complete action using' selector...

String url = "http://www.google.com/search?q=" + query; 
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

The default Android browser works, in that a browser opens at the specified URL. However, when I open using Chrome browser, Chrome simply opens... it seems to ignore the specified URL.

Is this a problem with Chrome, or my code?

Cheers

Upvotes: 5

Views: 1831

Answers (1)

Michael
Michael

Reputation: 524

The problem was my query variable. It appears Chrome did not accept the format of the query string, where the default Android browser did.

The get the code to work I had to URL encode the query...

query = URLEncoder.encode(query, "UTF-8");

Upvotes: 2

Related Questions