Search code examples
androideclipsegpsddms

Is there a way to test the loss of GPS provider on Android? (onProviderDisabled())


I'd like to test my LocationListener() fully on the emulator, to see if it works correctly in all circumstances. Is there a way to test onProviderDisabled() and onProviderEnabled() using the emulator?

    location_listener = new LocationListener(){

        public void onLocationChanged(Location location) {
            // Update application based on new location 
            updateLocation(location); 
        }

        public void onProviderDisabled(String provider) {
            // Update application if provider disabled
            setContentView(R.layout.lostgps);
        }

        public void onProviderEnabled(String provider) {
            // Update application if provider enabled 
            setContentView(R.layout.game); 
        }

        public void onStatusChanged(String provider, int status,
                Bundle extras) {
            // Update application if provider hardware status changed 
        }

    };

Solution

  • Yes, you can use LocationManager.setTestProviderEnabled() and LocationManager.setTestProviderStatus() to test the listener.