1

我有这个代码,它返回设备的所有已安装应用程序的列表:

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 服务的应用程序,据我所知,如果我可以过滤这些应用程序中获得的权限,那么我可以解决它,但不知道该怎么做。

4

1 回答 1

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));
}
}
于 2012-04-22T07:49:59.630 回答