- private void openApp(String packageName) {
- PackageInfo pi = getPackageManager().getPackageInfo(packageName, 0);
-
- Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
- resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
- resolveIntent.setPackage(pi.packageName);
-
- List<ResolveInfo> apps = pm.queryIntentActivities(resolveIntent, 0);
-
- ResolveInfo ri = apps.iterator().next();
- if (ri != null ) {
- String 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);
- }
- }
posted @
2017-10-20 10:27
小毛驴
阅读(
163)
评论()
编辑
收藏
举报