Android根据APP包名启动应用

     public void openApp(String packageName, Context context) {
PackageManager packageManager = context.getPackageManager();
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
resolveIntent.setPackage(packageName); List<ResolveInfo> apps = packageManager.queryIntentActivities(
resolveIntent, 0); ResolveInfo ri = apps.iterator().next();
if (ri != null) {
String className = ri.activityInfo.name; Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName(packageName, className); intent.setComponent(cn);
context.startActivity(intent);
}
}
上一篇:Java项目中的classpath


下一篇:WinForms 快速开发的工具类。