android中怎么启动app

2025-01-01 19:26:14
推荐回答(1个)
回答1:

通过包名获取此APP详细信息,包括Activities、services、versioncode、name等等
PackageInfo packageinfo = null;
try {
packageinfo = getPackageManager().getPackageInfo(packagename, 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
if (packageinfo == null) {
return;
}

// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
resolveIntent.setPackage(packageinfo.packageName);

// 通过getPackageManager()的queryIntentActivities方法遍历
List resolveinfoList = getPackageManager()
.queryIntentActivities(resolveIntent, 0);