最近因為項目需要,不讓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();
- }
-
- }
網上都有,不說了,目前只有這個能實現我的解決方案。其余的幾種方法網上都有,不多說了。