Get application names with specific permission

后端 未结 2 1812
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 09:19

I want list of all applications installed on the device which use a specific permission like INTERNET.

i am using this code , but not able to retrieve results , plea

相关标签:
2条回答
  • 2020-12-11 09:47

    I tried the code on android 2.2 emulator and it was working fine. Following is the working code:

    private ArrayList<String> getInstalledApps(Context context) {
            ArrayList<String> results = new ArrayList<String>();
            PackageManager packageManager = context.getPackageManager();
            List<PackageInfo> applist = packageManager.getInstalledPackages(0);
            Iterator<PackageInfo> it = applist.iterator();
            while (it.hasNext()) {
                PackageInfo pk = (PackageInfo) it.next();
                if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    Log.v("system app using internet = ", ""+pk.applicationInfo.loadLabel(packageManager));
                    continue;
                }
                if (PackageManager.PERMISSION_GRANTED == packageManager
                        .checkPermission(Manifest.permission.INTERNET,
                                pk.packageName))
                    results.add("" + pk.applicationInfo.loadLabel(packageManager));
            }
    
            Log.v("app using internet = ", results.toString());
    
            return results;
        }
    
    0 讨论(0)
  • 2020-12-11 09:56

    i had the same scenario, i solved it using the following check

    PackageInfo p = packs.get(i);
    ApplicationInfo a = p.applicationInfo;
    if (PackageManager.PERMISSION_GRANTED != pm.checkPermission(Manifest.permission.INTERNET, p.packageName)) {
    continue;
    }
    

    the packs variable is a array of class that holds information about the application installed and it consists of the objects with info of all the applications currently installed in system

    0 讨论(0)
提交回复
热议问题