我有这个代码,它返回设备的所有已安装应用程序的列表:
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> list =pm.queryIntentActivities(intent,PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm)
.toString());
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
.loadLabel(pm).toString());
}
但是现在我想只在我的列表中使用gps服务的那些应用程序,据我所知,如果我可以过滤那些应用程序中的权限,那么我可以解决它,但不知道如何做到这一点
答案 0 :(得分:3)
使用可以使用下面的代码片段:::
PackageManager packageManager=this.getPackageManager();
List<PackageInfo> applist=packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it=applist.iterator();
while(it.hasNext()){
PackageInfo pk=(PackageInfo)it.next();
if(PackageManager.PERMISSION_GRANTED==packageManager.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION, pk.packageName)) //checking if the package is having INTERNET permission
{
results.add(""+pk.applicationInfo.loadLabel(packageManager));
}
}