我的代码获取权限(已安装的应用程序所需)和其他 Android设备上安装的应用程序的详细信息,但它无法正常工作:
private void populateWithInitialApps() {
/* StringBuffer appNameAndPermissions = new StringBuffer();
String[] requestedPermissions = new String[]{};*/
// List<ApplicationInfo> appList = getPackageManager().getInstalledApplications(0);
// String name = pm.getApplicationLabel(appList.get(0)).toString();
//AppItem appItem = new AppItem(appList.get(0).packageName.toString(), appList.get(0).packageName.toString());
String requestedPermissions1 ;
for (int i = 0; i < noOfApps; i++) {
StringBuffer appNameAndPermissions = new StringBuffer();
String per= appList.get(0).permission;
String[] requestedPermissions= new String[]{};
requestedPermissions1 ="" ;
try {
PackageInfo packageInfo = pm.getPackageInfo(appList.get(i).packageName, PackageManager.GET_PERMISSIONS);
; ;/*packageInfo.requestedPermissions;*/
// if (requestedPermission1s != null) {
// requestedPermissions = new String[]{};
// int j = 0 ;
requestedPermissions = packageInfo.requestedPermissions;
Log.v("lentth",String.valueOf(requestedPermissions.length));
for (int j = 0; j < requestedPermissions.length; j++) {
// appNameAndPermissions=new StringBuffer();
Log.d("test", requestedPermissions[j]);
appNameAndPermissions.append(requestedPermissions[j] + "\n");
}
/* while (j<requestedPermissions.length)
{
Log.d("test", requestedPermissions[j]);
requestedPermissions1.concat(" "+requestedPermissions[j]);
j++ ;
}*/
//}
}
catch (PackageManager.NameNotFoundException e)
{
}
itemList.add( new AppItem(appList.get(i).packageName.toString(),requestedPermissions1,String.valueOf(appList.get(0).targetSdkVersion),
pm.getApplicationLabel(appList.get(i)).toString()));
}
}
返回以下错误:
requestPermission.length
java.lang.NullPointerException:尝试获取null数组的长度