Tae-Sung Shin
Tae-Sung Shin

Reputation: 20643

Location service does not work in a real android device

My test app that finds current location of the device is working fine in emulator. That is, when in my DDMS in eclipse, I send the location coordinates to the emulator, the app catches the broadcast and displays the location in the map in emulator. But in my real 2.3.3 android device, the app just hangs while gps is blinking in notification bar. Here is what I am doing in my service class

public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    Log.e("<<MyGpsService-onStart>>", "GPS starting...");
    triggerService = new Thread(new Runnable() {
        public void run() {
            try {
                Looper.prepare();
                lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                myLocationListener = new GPSListener();
                long minTime = 10000; // frequency update: 10 seconds
                float minDistance = 50; // frequency update: 50 meter
                lm.requestLocationUpdates(
                        // request GPS updates
                        LocationManager.GPS_PROVIDER, minTime, minDistance,
                        myLocationListener);
                Looper.loop();
            } catch (Exception e) {
                Log.e("MYGPS", e.getMessage());
            }
        }// run
    });
    triggerService.start();
}
class GPSListener implements LocationListener {
    public void onLocationChanged(Location location) {
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();

        Intent myFilteredResponse = new Intent(GPS_FILTER);
        myFilteredResponse.putExtra("latitude", latitude);
        myFilteredResponse.putExtra("longitude", longitude);
        Log.e(">>GPS_Service<<", "Lat:" + latitude + " lon:" + longitude);

        sendBroadcast(myFilteredResponse);
    }

    public void onProviderDisabled(String provider) {
    }

    public void onProviderEnabled(String provider) {
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
};// GPSListenerclass

I wonder if any of you have a similar problem. Thanks.

UPDATE: I followed following question and answer:

Android - Reliably getting the current location

After the change, the app is working a lot better.

Upvotes: 1

Views: 1560

Answers (2)

Fernando Gallego
Fernando Gallego

Reputation: 4116

GPS does not work inside buildings. DDMS location only works for the emulator

Upvotes: 2

Kurtis Nusbaum
Kurtis Nusbaum

Reputation: 30825

Are you getting anything interesting in the logcat for your device? You can view the logcat of the actual device using adb.

Upvotes: 2

Related Questions