7

I am trying to find piece of code which can tell me whether the android phone has GPS device or not? Most of the samples I am getting in search results are telling whether GPS is enabled or not. What I am interested in is whether Android phone has Physical GPS device or not?

Thanks

Haris Hasan
  • 29,856
  • 10
  • 92
  • 122

2 Answers2

21

Starting with API level 8 (Froyo), you can use the following code:

PackageManager packageManager = mContext.getPackageManager();
boolean hasGPS = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
Daniel
  • 984
  • 8
  • 14
11
public boolean hasGPSDevice(Context context)
    {
    final LocationManager mgr = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
    if ( mgr == null ) return false;
    final List<String> providers = mgr.getAllProviders();
    if ( providers == null ) return false;
    return providers.contains(LocationManager.GPS_PROVIDER);
    }
Damian Kołakowski
  • 2,731
  • 22
  • 25
  • 1
    + 1 Your answer makes sense. But in the emulator even if I do `GPS Support = No` this code returns true. Any ideas? May be this will work well on a phone without GPS it will return false but not sure... – Haris Hasan Jul 12 '11 at 13:12