domingo, 14 de octubre de 2012

How can I open a URL in Android's web browser from my application?


Problem:

When the user clicks on an option menu I want to open an url using Android's default web browser.

Solution:


Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
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://".

No hay comentarios:

Publicar un comentario