android检测手机是否有某个应用以及启动安装另一个应用的问题
/** * 获取所有应用的名称,包名,以及权限 有了包名就可以判断是否有某个应用了 */ List<PackageInfo> list = getPackageManager().getInstalledPackages(PackageManager.GET_PERMISSIONS); StringBuilder stringBuilder = new StringBuilder(); for (PackageInfo packageInfo : list) { stringBuilder.append("package name:"+ packageInfo.packageName + "\n"); ApplicationInfo applicationInfo = packageInfo.applicationInfo; stringBuilder.append("应用名称:"+ applicationInfo.loadLabel(getPackageManager()) + "\n"); if (packageInfo.permissions != null) { for (PermissionInfo p : packageInfo.permissions) { stringBuilder.append("权限包括:" + p.name + "\n"); } } stringBuilder.append("\n"); }
// 通过Intent安装APK文件 Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse("file://" + apkfile.toString()), "application/vnd.android.package-archive"); mContext.startActivity(i);
huidaoli版权所有:转载请注明出处,谢谢合作!