check if device supports GPS - Android Hardware

Android examples for Hardware:Gps

Description

check if device supports GPS

Demo Code


//package com.java2s;

import java.util.List;

import android.content.Context;

import android.location.LocationManager;

public class Main {

    public static boolean hasGPSDevice(Context context) {
        final LocationManager mgr = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);
        if (mgr == null) {
            return false;
        }//from   w  ww .  jav  a  2 s.co  m
        final List<String> providers = mgr.getAllProviders();
        if (providers == null) {
            return false;
        }
        if (providers.contains(LocationManager.GPS_PROVIDER)
                || providers.contains(LocationManager.NETWORK_PROVIDER)) {
            return true;
        }
        return false;
    }
}

Related Tutorials