Android browser without URL

How can I launch a browser from an activity without specifying a URL. I would like to open the browser so that the user can continue browsing without changing the page on which they were.

SOLUTION: The answer below was correct and worked out, but for more specific readers, the working code should be given here:

Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setAction("com.android.browser");
ComponentName comp = new ComponentName("com.android.browser", "com.android.browser.BrowserActivity");
i.setComponent(comp);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

Thank!

+5
source share
3 answers

Use Intent # setComponent () to install the browser package and class name. Then run the action.

+4
source

, (ComponentName ( "com.android.browser", "com.android.browser.BrowserActivity" )) , - :

public static ComponentName getDefaultBrowserComponent(Context context) {
    Intent i = new Intent()
        .setAction(Intent.ACTION_VIEW)
        .setData(new Uri.Builder()
                .scheme("http")
                .authority("x.y.z")
                .appendQueryParameter("q", "x")
                .build()
                );
    PackageManager pm = context.getPackageManager();
    ResolveInfo default_ri = pm.resolveActivity(i, 0); // may be a chooser
    ResolveInfo browser_ri = null;
    List<ResolveInfo> rList = pm.queryIntentActivities(i, 0);
    for (ResolveInfo ri : rList) {
        if (ri.activityInfo.packageName.equals(default_ri.activityInfo.packageName)
         && ri.activityInfo.name.equals(default_ri.activityInfo.name)
        ) {
            return ri2cn(default_ri);
        } else if ("com.android.browser".equals(ri.activityInfo.packageName)) {
            browser_ri = ri;
        }
    }
    if (browser_ri != null) {
        return ri2cn(browser_ri);
    } else if (rList.size() > 0) {
        return ri2cn(rList.get(0));
    } else if (default_ri == null) {
        return null;
    } else {
        return ri2cn(default_ri);
    }
}
private static ComponentName ri2cn(ResolveInfo ri) {
    return new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name);
}

, http-, , , , resolveActivity() -. , Launcher ( VIEW), , , .

+2

. Android URL-?

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);
+2
source

All Articles