Android的意图打开用户的preferred浏览器 [英] Android intent to open user's preferred browser

查看:140
本文介绍了Android的意图打开用户的preferred浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出如何创建一个意图,这将打开用户的preferred的浏览器,而无需指定的URL。我知道如何通过给特定的URL像这样打开它:

I've been trying to find out how to create an intent that will open the user's preferred browser without specifying the URL. I know how to open it by giving a specific URL like this:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(android.net.Uri.parse("http://www.google.com"));
context.startActivity(intent);

我不希望打开浏览器尤其是刚刚设置的主页或其他页面的用户是在最后的页面。我也想过找了网页应用程序中设置,但你不能使用默认的浏览器应用程序做,因为这是私人的。有谁知道的一种方式做到这一点?

I don't want to open the browser to any page in particular, just the set homepage or whatever page the user was on last. I've thought about looking up the homepage set within the app but you can't do it with the default Browser app because it is private. Does anybody know of a way to do this?

推荐答案

下面是我如何做的:

String packageName = "com.android.browser"; 
String className = "com.android.browser.BrowserActivity"; 
Intent internetIntent = new Intent(Intent.ACTION_VIEW);
internetIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
internetIntent.setClassName(packageName, className); 
mHomeActivity.startActivity(internetIntent);

如果你有没有主页设置,它会打开一个空白页(至少在Android 2.1系统)。

If you have no homepage set, it'll open a blank page (at least in Android 2.1).

这篇关于Android的意图打开用户的preferred浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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