9

I am trying to find some code which will help me to find out if the device which I use has GPS or not? I don't want to know if GPS is enabled or disabled. I just want to know if the device has GPS hardware or not through my program.

Janusz
  • 187,060
  • 113
  • 301
  • 369
Hare-Krishna
  • 1,425
  • 3
  • 16
  • 26
  • Note: You should probably "accept" some answers to your previous questions. You do this by clicking the green "tick" icon next to the best answer. – Christopher Orr Apr 06 '10 at 13:09

3 Answers3

18

Yes, this can be done.

You can call LocationManager.getAllProviders() and check whether LocationManager.GPS_PROVIDER is included in the list.

Just for reference, I believe all released Android phones come with a GPS. It's not something that Android seem to be worrying about, e.g. mentioning GPS as one of the device attributes returned by PackageManager.getSystemAvailableFeatures().

Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
  • They do currently all have GPS but some tablets in the future might not (I think the K-Mart tablet doesn't actually). – matto1990 Aug 03 '10 at 08:33
  • @RockOn If you find this answered your question, can you accept it? – a_hardin Oct 06 '11 at 18:16
  • 1
    @Mike: The Kindle Fire didn't exist in April 2010, but as of SDK version 8 you can use the `PackageManager.FEATURE_LOCATION_GPS` constant with the `getSystemAvailableFeatures()` method mentioned here. – Christopher Orr Jul 04 '12 at 19:43
  • Many low cost phones of *itel* manufacturer from China do have Android without any GPS sensor; an example is their model it1353. – 1111161171159459134 Jun 18 '15 at 01:02
  • @DanielBeauyat Indeed. But that wasn't the case over five years ago when I wrote this answer, as you can also see from the comment above yours. – Christopher Orr Jun 18 '15 at 01:51
10

Those methods are easier to use:

private boolean hasGpsSensor(){
        PackageManager packMan = getPackageManager();
        return packMan.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
}
  • true: available (activated or not)
  • false: not available

So, in case of true, we can use

private boolean isGpsEnabled(){
        LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        return manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
  • true: enabled
  • false: disabled

With this two, you will know if GPS is available, activated or deactivated

AxelH
  • 14,325
  • 2
  • 25
  • 55
3

There's also LocationManager.isProviderEnabled(String provider) method.

Fedor
  • 43,261
  • 10
  • 79
  • 89
  • 4
    This is a wrong answer. Quote from question: "I don't want to know if GPS is enabled or disabled.". – Namenlos Aug 15 '13 at 13:09