How do I detect an Android Tablet device that lacks GPS?
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_S开发者_如何学运维ERVICE);
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.
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)
<uses-feature android:name="android.hardware.location.gps" android:required="true" />
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:
LocationManager.getProvider(LocationManager.GPS_PROVIDER)
will return null.
精彩评论