问题
I would like to enable the location settings on an android machine. In my program I check if the
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
..//
}
If deactive, I would like to activate it programatically.
EDIT: When my location settings are disabled and I call/use googleMaps, I am asked by means of a dialog, whether I want to enable it? If "Yes", the location service is being enabled in the background without callings another user interaction.
Can I enable location settings without having other user interactions?
回答1:
No you cannot. location information is build into the system, which require permission. Android M currently has "permission" build for each app that can set it when app starts. But if user forcefully turn off GPS then the user has to turn it back on him/herself.
来源:https://stackoverflow.com/questions/35287714/how-to-enable-location-on-android-in-program-code