Android examples for Network:URL
choice Browser To Visit Url
//package com.book2s; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.net.Uri; import java.util.List; public class Main { public static void choiceBrowserToVisitUrl(Context context, String url) { boolean existUC = false, existOpera = false, existQQ = false, existDolphin = false, existSkyfire = false, existSteel = false, existGoogle = false; String ucPath = "", operaPath = "", qqPath = "", dolphinPath = "", skyfirePath = "", steelPath = "", googlePath = ""; PackageManager packageMgr = context.getPackageManager(); List<PackageInfo> list = packageMgr.getInstalledPackages(0); for (int i = 0; i < list.size(); i++) { PackageInfo info = list.get(i); String temp = info.packageName; if (temp.equals("com.uc.browser")) { // ??UC ucPath = temp;/*from w w w . j a v a 2 s . c o m*/ existUC = true; } else if (temp.equals("com.tencent.mtt")) { // ??QQ qqPath = temp; existQQ = true; } else if (temp.equals("com.opera.mini.android")) { // ??Opera operaPath = temp; existOpera = true; } else if (temp.equals("mobi.mgeek.TunnyBrowser")) { dolphinPath = temp; existDolphin = true; } else if (temp.equals("com.skyfire.browser")) { skyfirePath = temp; existSkyfire = true; } else if (temp.equals("com.kolbysoft.steel")) { steelPath = temp; existSteel = true; } else if (temp.equals("com.android.browser")) { // ??GoogleBroser googlePath = temp; existGoogle = true; } } if (existUC) { gotoUrl(context, ucPath, url, packageMgr); } else if (existOpera) { gotoUrl(context, operaPath, url, packageMgr); } else if (existQQ) { gotoUrl(context, qqPath, url, packageMgr); } else if (existDolphin) { gotoUrl(context, dolphinPath, url, packageMgr); } else if (existSkyfire) { gotoUrl(context, skyfirePath, url, packageMgr); } else if (existSteel) { gotoUrl(context, steelPath, url, packageMgr); } else if (existGoogle) { gotoUrl(context, googlePath, url, packageMgr); } else { doDefault(context, url); } } private static void gotoUrl(Context context, String packageName, String url, PackageManager packageMgr) { try { Intent intent; intent = packageMgr.getLaunchIntentForPackage(packageName); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse(url)); context.startActivity(intent); } catch (Exception e) { e.printStackTrace(); } } private static void doDefault(Context context, String visitUrl) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(visitUrl)); context.startActivity(intent); } }