Android 11 获取app列表发现,只能获取系统安装的类别,其他新装的无法获取到,原因在于权限不够
代码如下
```
List<PackageInfo> packages = context.getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
for (int i = 0; i < packages.size(); i++) {
PackageInfo packageInfo = packages.get(i);
String appName = packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString();
String packageName = packageInfo.packageName;
String versionName = packageInfo.versionName;
Log.d("anger",appName);
Log.d("anger",packageName);
Log.d("anger",versionName);
}
```
增加权限
```
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
```
参考地址https://stackoverflow.com/questions/67189934/how-to-get-a-list-of-installed-apps-in-android-11