如何打开默认的Andr​​oid浏览器,而无需指定的网址是什么? [英] How to open the default android browser without specifying an URL?

查看:89
本文介绍了如何打开默认的Andr​​oid浏览器,而无需指定的网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我失去我的脑海里这一点。我想打开用户的默认Web浏览器。我可以用这样的:

I'm loosing my mind over this. I want to open the user's default web browser. I can use this:

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

要打开浏览器,向用户发送该URL。但我不想送他到一个特定的网址,我只是想打开浏览器。我敢肯定,这是一个简单的解决方案,我只是无法找到它。任何想法?

To open the browser and send the user to that URL. But I don't want to send him to a specific URL, I just want to open the browser. I'm sure it's a simple solution, I just can't find it. Any Ideas?

推荐答案

一堆的寻找后,我能够做到这一点:

After a bunch of searching, I was able to do this:

PackageManager pm = getPackageManager();
Intent queryIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
ActivityInfo af = queryIntent.resolveActivityInfo(pm, 0);
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.setClassName(af.packageName, af.name);
startActivity(launchIntent);

这基本上说什么应用程序将处理呢?。然后,它抓住了应用程序包和类的名称,则触发意向的主要动作。

It basically says "What application would handle this?". Then it grabs that applications package and class name then fires an intent for the main action.

这篇关于如何打开默认的Andr​​oid浏览器,而无需指定的网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆