如何在程序代码中启用Android上的位置? [英] How to enable location on Android in program code?

查看:69
本文介绍了如何在程序代码中启用Android上的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android机器上启用位置设置.在我的程序中,我检查

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.

当我的位置设置被禁用并且我调用/使用googleMaps时,会通过对话框询问我是否要启用它?如果为是",则在后台启用位置服务,而无需调用其他用户交互.

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.

是否可以在没有其他用户交互的情况下启用位置设置?

推荐答案

不,您不能.位置信息已内置到系统中,需要获得许可.Android M当前为每个应用程序都具有权限"构建,可以在应用程序启动时对其进行设置.但是,如果用户强行关闭GPS,则用户必须将其重新打开.

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.

这篇关于如何在程序代码中启用Android上的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆