How to enable location on Android in program code?

大兔子大兔子 提交于 2021-02-11 06:42:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!