Envío de una Intent al navegador para abrir una URL específica [duplicar]


Esta pregunta ya tiene una respuesta aquí:

Me pregunto cómo activar una Intent en el navegador del teléfono para abrir una URL específica y mostrarla.

¿Puede alguien por favor darme una pista?

Author: Rakete1111, 2010-06-09

10 answers

Para abrir una URL / sitio web, haga lo siguiente:

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

Aquí está la documentación de Intent.ACTION_VIEW.


Fuente: Abrir una URL en el navegador web de Android desde la aplicación

 1532
Author: aioobe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-29 04:01:51

La versión corta

Intent i = new Intent(Intent.ACTION_VIEW, 
       Uri.parse("http://almondmendoza.com/android-applications/"));
startActivity(i);

Debería funcionar también...

 168
Author: Juri,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-08-04 20:21:34

La versión más corta.

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")));
 136
Author: Gianluca,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-25 12:12:02

En algunos casos URL puede comenzar con "www". En este caso obtendrá una excepción:

android.content.ActivityNotFoundException: No Activity found to handle Intent

La URL siempre debe comenzar con " http: / / "o" https: / / " así que uso este fragmento de código:

if (!url.startsWith("https://") && !url.startsWith("http://")){
    url = "http://" + url;
}
Intent openUrlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(openUrlIntent);
 76
Author: Bakyt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-11 11:30:23

Enviando una Intent al Navegador para abrir una URL específica:

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

Podría cambiarse a una versión de código corto ...

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

O

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

O incluso más corto!

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

Más información sobre Intención

=)

 35
Author: Jorgesys,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-11 19:34:59

¿Hay también una manera de pasar coords directamente a google maps para mostrar?

Puede usar el geo URI prefijo:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:" + latitude + "," + longitude));
startActivity(intent);
 24
Author: Phil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-12-21 01:52:15

Desde XML

En caso de que tenga la dirección web/URL mostrada en su vista y desee que se pueda clikear y dirigir al usuario a un sitio web en particular, puede usar:

android:autoLink="web"

De la misma manera puede utilizar diferentes atributos de AutoLink(correo electrónico, teléfono, mapa, todos) para llevar a cabo su tarea...

 11
Author: Saty,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-04 07:52:19

" ¿Hay también una manera de pasar coords directamente a google maps para mostrar?"

He encontrado que si paso una URL que contiene los coords al navegador, Android pregunta si quiero el navegador o la aplicación Maps, siempre y cuando el usuario no haya elegido el navegador como predeterminado. Vea mi respuesta aquí para obtener más información sobre la configuración de la URL.

Supongo que si usaras una intent para iniciar la aplicación Maps con los coords, eso también funcionaría.

 6
Author: Kingsolmn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:18:23
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
 6
Author: Sunil Pandey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-25 12:11:19

Utilice el siguiente fragmento en su código

Intent newIntent = new Intent(Intent.ACTION_VIEW, 
Uri.parse("https://www.google.co.in/?gws_rd=cr"));
startActivity(newIntent);

Utilice Este enlace

Http://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW

 4
Author: XYZ_deve,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-16 10:38:20