To know if the GPS is on use this code:
LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
bool isOn = manager.isProviderEnabled( LocationManager.GPS_PROVIDER);
I do not think there is any way of knowing which applications are currently using GPS.
It is possible, however, to know which applications are allowed to use it:
PackageManager p = context.getPackageManager();
List<PackageInfo> appInstaladas = p.getInstalledPackages(PackageManager.GET_PERMISSIONS);
This code fills the list appInstaladas
with information about installed applications, including their permissions.
For the list of permissions use, for each of the appInstaladas
:
//Retorna permissões declaradas em <uses-permission>
String[] requestedPermissions = appInstaladas.get(index).requestedPermissions();
//Retorna permissões declaradas em <permission>
PermissionInfo[] permissions = appInstaldas.get(index).permissions();
Sources:
PackageInfo.requestedPermissions
Packageinfo.Permissions
SO AS.
Thank you very much Ramaral I will test abs...
– Klever Cavalcanti