private void runApp(String packageName) {
PackageInfo pi;
try {
pi = getPackageManager().getPackageInfo(packageName, 0);
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
resolveIntent.setPackage(pi.packageName);
PackageManager pManager = getPackageManager();
List<ResolveInfo> apps = pManager.queryIntentActivities(
resolveIntent, 0);
ResolveInfo ri = (ResolveInfo) apps.iterator().next();
if (ri != null) {
packageName = ri.activityInfo.packageName;
String className = ri.activityInfo.name;
Intent intent = new Intent(Intent.ACTION_MAIN);
ComponentName cn = new ComponentName(packageName, className);
intent.setComponent(cn);
startActivity(intent);
}
} catch (NameNotFoundException e) {
ToastUtil.show(context, "尚未安装此应用");
}
}
通过应用程序包名打开应用
最新推荐文章于 2024-06-05 11:22:26 发布