Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check whether the phone has GPS device or not?

Tags:

android

gps

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

like image 937
Haris Hasan Avatar asked Jul 12 '11 12:07

Haris Hasan


2 Answers

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

PackageManager packageManager = mContext.getPackageManager();
boolean hasGPS = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
like image 66
Daniel Avatar answered Sep 24 '22 21:09

Daniel


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);
    }
like image 38
Damian Kołakowski Avatar answered Sep 24 '22 21:09

Damian Kołakowski