如何以编程方式打开 Android 上的 GPS
How to programmatically turn on GPS on Android
我调查了一些关于 Whosebug 的文章。
看来 android 4.0 以上的版本无法以编程方式打开 on/off GPS。
现在有什么变化吗?或者这仍然不可能?
出于安全原因,您无法以编程方式on/off 关闭它。根据 Change location settings 文档:
If your app needs to request location or receive permission updates, the device needs to enable the appropriate system settings, such as GPS or Wi-Fi scanning. Rather than directly enabling services such as the device's GPS, your app specifies the required level of accuracy/power consumption and desired update interval, and the device automatically makes the appropriate changes to system settings.
所以,最好的办法是,如果用户禁用了 GPS,那么为了获得更好的用户体验,您可以显示提示并将用户重定向到位置 activity,如下所示:
MainActivity.Instance.StartActivity(new Intent(ActionLocationSourceSettings));
其中 MainActivity.Instance
是您当前的 Activity。
我调查了一些关于 Whosebug 的文章。
看来 android 4.0 以上的版本无法以编程方式打开 on/off GPS。
现在有什么变化吗?或者这仍然不可能?
出于安全原因,您无法以编程方式on/off 关闭它。根据 Change location settings 文档:
If your app needs to request location or receive permission updates, the device needs to enable the appropriate system settings, such as GPS or Wi-Fi scanning. Rather than directly enabling services such as the device's GPS, your app specifies the required level of accuracy/power consumption and desired update interval, and the device automatically makes the appropriate changes to system settings.
所以,最好的办法是,如果用户禁用了 GPS,那么为了获得更好的用户体验,您可以显示提示并将用户重定向到位置 activity,如下所示:
MainActivity.Instance.StartActivity(new Intent(ActionLocationSourceSettings));
其中 MainActivity.Instance
是您当前的 Activity。