首先遍历手机内应用,找到需要的应用包名:
/** * 遍历手机内应用包名 * @param context */ @H_403_16@public @H_403_16@static @H_403_16@voID loadApps(Context context) { Intent intent = @H_403_16@new Intent(Intent.ACTION_MAIN,@H_403_16@null); intent.addcategory(Intent.category_LAUNCHER); List<ResolveInfo> apps = context.getPackageManager().queryIntentActivitIEs(intent,0); //for循环遍历ResolveInfo对象获取包名和类名 @H_403_16@for (@H_403_16@int i = 0; i < apps.size(); i++) { ResolveInfo info = apps.@H_403_16@get(i); String packagename = info.activityInfo.packagename; CharSequence cls = info.activityInfo.name; CharSequence name = info.activityInfo.loadLabel(context.getPackageManager()); Log.e("wgh!!!!!",name + "----" + packagename + "----" + cls); } }
/** * 启动到app详情界面 * * @param appPkg * App的包名 * @param marketPkg * 应用商店包名,如果为""则由系统d出应用商店列表供用户选择,否则调转到目标市场的应用详情界面,某些应用商店可能会失败 */ @H_403_16@public @H_403_16@static @H_403_16@voID launchAppDetail(Context context,String appPkg,String marketPkg) { Intent intent = @H_403_16@new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?ID=" + appPkg)); String[] keys = getKeys(context); @H_403_16@if (keys != @H_403_16@null) { intent.setClassname(keys[0],keys[1]); } //修复某些老手机会因为找不到任何市场而报错 @H_403_16@if (isIntentAvailable(context,intent)) { context.startActivity(intent); } @H_403_16@else { ToastUtil.showToast("应用市场不存在"); } } @H_403_16@private @H_403_16@static String[] getKeys(Context context) { String[] keys = @H_403_16@new String[2]; @H_403_16@if (isPackageExist(context,PACKAGE_MI_MARKET)) { keys[0] = PACKAGE_MI_MARKET; keys[1] = MI_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_VIVO_MARKET)) { keys[0] = PACKAGE_VIVO_MARKET; keys[1] = VIVO_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_OPPO_MARKET)) { keys[0] = PACKAGE_OPPO_MARKET; keys[1] = OPPO_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_HUAWEI_MARKET)) { keys[0] = PACKAGE_HUAWEI_MARKET; keys[1] = HUAWEI_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_ZTE_MARKET)) { keys[0] = PACKAGE_ZTE_MARKET; keys[1] = ZTE_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_COol_MARKET)) { keys[0] = PACKAGE_COol_MARKET; keys[1] = COol_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_360_MARKET)) { keys[0] = PACKAGE_360_MARKET; keys[1] = PACKAGE_360_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_MEIZU_MARKET)) { keys[0] = PACKAGE_MEIZU_MARKET; keys[1] = MEIZU_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_TENCENT_MARKET)) { keys[0] = PACKAGE_TENCENT_MARKET; keys[1] = TENCENT_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_Ali_MARKET)) { keys[0] = PACKAGE_Ali_MARKET; keys[1] = Ali_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_WANDOUJIA_MARKET)) { keys[0] = PACKAGE_WANDOUJIA_MARKET; keys[1] = WANDOUJIA_MARKET_PAGE; } @H_403_16@else @H_403_16@if (isPackageExist(context,PACKAGE_UCWEB_MARKET)) { keys[0] = PACKAGE_UCWEB_MARKET; keys[1] = UCWEB_MARKET_PAGE; } @H_403_16@if (TextUtils.isEmpty(keys[0])) { @H_403_16@return @H_403_16@null; } @H_403_16@else { @H_403_16@return keys; } } /** * @param context * @param packagename * @return * @Title isPackageExist * @Description .判断package是否存在 * @date 2013年12月31日 上午9:49:59 */ @H_403_16@public @H_403_16@static boolean isPackageExist(Context context,String packagename) { PackageManager manager = context.getPackageManager(); Intent intent = @H_403_16@new Intent().setPackage(packagename); List<ResolveInfo> infos = manager.queryIntentActivitIEs(intent,PackageManager.GET_INTENT_FILTERS); @H_403_16@if (infos == @H_403_16@null || infos.size() < 1) { @H_403_16@return @H_403_16@false; } @H_403_16@else { @H_403_16@return @H_403_16@true; } } /** * 检测 响应某个Intent的Activity 是否存在 * @param context * @param intent * @return */ @Suppresslint("WrongConstant") @H_403_16@public @H_403_16@static boolean isIntentAvailable(Context context,Intent intent) { final PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> List = packageManager.queryIntentActivitIEs(intent,PackageManager.GET_ACTIVITIES); @H_403_16@return List.size() > 0; }
应用市场包名:
//小米应用商店 @H_403_16@public @H_403_16@static final String PACKAGE_MI_MARKET = "com.xiaomi.market"; @H_403_16@public @H_403_16@static final String MI_MARKET_PAGE = "com.xiaomi.market.ui.AppDetailActivity"; //魅族应用商店 @H_403_16@public @H_403_16@static final String PACKAGE_MEIZU_MARKET = "com.meizu.mstore"; @H_403_16@public @H_403_16@static final String MEIZU_MARKET_PAGE = "com.meizu.flyme.appcenter.activitys.AppMainActivity"; //VIVO应用商店 @H_403_16@public @H_403_16@static final String PACKAGE_VIVO_MARKET = "com.bbk.appstore"; @H_403_16@public @H_403_16@static final String VIVO_MARKET_PAGE = "com.bbk.appstore.ui.AppStoretabactivity"; //OPPO应用商店 @H_403_16@public @H_403_16@static final String PACKAGE_OPPO_MARKET = "com.oppo.market"; @H_403_16@public @H_403_16@static final String OPPO_MARKET_PAGE = "a.a.a.aoz"; //华为应用商店 @H_403_16@public @H_403_16@static final String PACKAGE_HUAWEI_MARKET = "com.huawei.appmarket"; @H_403_16@public @H_403_16@static final String HUAWEI_MARKET_PAGE = "com.huawei.appmarket.service.externalAPI.vIEw.ThirdAPIActivity"; //ZTE应用商店 @H_403_16@public @H_403_16@static final String PACKAGE_ZTE_MARKET = "zte.com.market"; @H_403_16@public @H_403_16@static final String ZTE_MARKET_PAGE = "zte.com.market.vIEw.zte.drain.ZtDrainTrafficActivity"; //360手机助手 @H_403_16@public @H_403_16@static final String PACKAGE_360_MARKET = "com.qihoo.appstore"; @H_403_16@public @H_403_16@static final String PACKAGE_360_PAGE = "com.qihoo.appstore.distribute.SearchdistributionActivity"; //酷市场 -- 酷安网 @H_403_16@public @H_403_16@static final String PACKAGE_COol_MARKET = "com.coolapk.market"; @H_403_16@public @H_403_16@static final String COol_MARKET_PAGE = "com.coolapk.market.activity.AppVIEwActivity"; //应用宝 @H_403_16@public @H_403_16@static final String PACKAGE_TENCENT_MARKET = "com.tencent.androID.qqdownloader"; @H_403_16@public @H_403_16@static final String TENCENT_MARKET_PAGE = "com.tencent.pangu.link.linkProxyActivity"; //PP助手 @H_403_16@public @H_403_16@static final String PACKAGE_Ali_MARKET = "com.pp.assistant"; @H_403_16@public @H_403_16@static final String Ali_MARKET_PAGE = "com.pp.assistant.activity.MainActivity"; //豌豆荚 @H_403_16@public @H_403_16@static final String PACKAGE_WANDOUJIA_MARKET = "com.wandoujia.phoenix2"; @H_403_16@public @H_403_16@static final String WANDOUJIA_MARKET_PAGE = "com.pp.assistant.activity.PPMainActivity"; //UCWEB @H_403_16@public @H_403_16@static final String PACKAGE_UCWEB_MARKET = "com.UCMobile"; @H_403_16@public @H_403_16@static final String UCWEB_MARKET_PAGE = "com.pp.assistant.activity.PPMainActivity";总结
以上是内存溢出为你收集整理的Android 遍历手机应用,跳转应用市场详情页面全部内容,希望文章能够帮你解决Android 遍历手机应用,跳转应用市场详情页面所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)