最近因为项目需要,不让app在应用列表显示,只能用自己的启动器启动。基本搞定,效果实现了,不过与我的计划相差挺远的。
private void RunApp(String packageName) { PackageInfo pi; try { pi = getPackageManager().getPackageInfo(packageName, 0); Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); // resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); resolveIntent.setPackage(pi.packageName); PackageManager pManager = getPackageManager(); List<ResolveInfo> apps = pManager.queryIntentActivities( resolveIntent, 0); ResolveInfo ri = apps.iterator().next(); if (ri != null) { packageName = ri.activityInfo.packageName; String className = ri.activityInfo.name; Intent intent = new Intent(Intent.ACTION_MAIN); // intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName(packageName, className); intent.setComponent(cn); startActivity(intent); } } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }网上都有,不说了,目前只有这个能实现我的解决方案。其余的几种方法网上都有,不多说了。