-1

I'm developing an app on Android OS.

I need a method that returns the list of apps that rely on location services/GPS

Mrunal
  • 195
  • 1
  • 1
  • 10

1 Answers1

5

You can use the code (from here) to get list of permissions of installed apps on the device. Then search for the required permissions about location services like ACCESS_FINE_LOCATION. Your code would be something like this:

PackageManager pm = getPackageManager();
List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : packages) {
    Log.d("test", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);
    try {
        PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);
        //Get Permissions
        String[] requestedPermissions = packageInfo.requestedPermissions;
        if(requestedPermissions != null) {
            for (int i = 0; i < requestedPermissions.length; i++) {
                Log.d("test", requestedPermissions[i]);

                //////////////////////////////////////
                //////////////////////////////////////
                // Look for the desired permission here
                //////////////////////////////////////
                //////////////////////////////////////
            }
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

And to do so, you need the following in your manifest:

<uses-permission android:name="android.permission.GET_TASKS"/>
Community
  • 1
  • 1
EmJiHash
  • 623
  • 9
  • 22
  • This is marvellous. is it also possible to find out the list of apps for which a specific permission is granted? – Mrunal Mar 15 '16 at 23:24
  • @Mrunal It's what I believe the above code is doing. You have list of the apps and their permissions, so you can filter it as you want. And you can mark the answer as accepted I guess. – EmJiHash Mar 15 '16 at 23:28