如何检测没有 GPS 的 Android 平板电脑设备?
我有 Android 平板电脑用户报告说,他们无法使用我的应用程序,因为他们缺少 GPS。我本来期望这个调用:
(LocationManager) getSystemService(LOCATION_SERVICE);
在此类设备上返回 null,但根据我的现场用户的报告,情况可能并非如此。
我缺少一款无 GPS 的 Android 平板电脑设备;有人可以告诉我如何检测我何时在这样的设备上运行,最好使用 1 行或 2 行代码片段吗?
非常感谢。
I have Android tablet users reporting that they are unable to use my app because they lack GPS. I would have expected this call:
(LocationManager) getSystemService(LOCATION_SERVICE);
To return null on such devices, but given reports from my users in the field that may not be the case.
I lack one of these GPS-free android tablet devices; can someone out there with one tell me how to detect when I am running on such a device, ideally with a 1 or 2-line code snippet?
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
位置管理器还可以使用网络来确定位置,因此即使设备没有 GPS,您仍然可以获得(粗略的)位置。
如果您想要求用户拥有 GPS,那么最好的方法是在您的 AndroidManifest 中包含使用功能标签:(文档:http://developer.android.com/guide/topics/manifest/uses-feature-element.html)
所需的标记允许您阻止它们从应用程序或只是到告诉他们这是必需的。
但直接回答你的问题,如果你想使用 LocationProvider 来测试是否有 GPS 那么:
将返回 null。
the Location manager can also use the network to determine location, so even if a device doesnt have gps you may still be able to get the (rougher) location.
if you want to require user to have gps then the best way is to include a uses-feature tag in your AndroidManifest: (the docs: http://developer.android.com/guide/topics/manifest/uses-feature-element.html)
the required tag allows you to block them from the app or just to advise them that its required.
but in direct answer to your question if you want to use LocationProvider to test if there is GPS then:
will return null.