Android的意图打开用户的preferred浏览器意图、浏览器、用户、Android

2023-09-04 05:07:38 作者:囿尓、狠緈諨

我一直在试图找出如何创建一个意图,这将打开用户的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).