0

I now create an app to detect the location of device through GPS, I have problem with GPS status, I look through the GpsStatus.Listener but it's complicated since I'm a newbie with Android.

HERE IS WHAT I TRY TO DO WITH GPS STATUS AM I ON THE RIGHT TRACK ???

    final Listener onGpsStatusChange = new GpsStatus.Listener() {

        @Override
        public void onGpsStatusChanged(int event) {
            // TODO Auto-generated method stub
            switch(event){
            case GpsStatus.GPS_EVENT_STARTED:
            // Started...
            break ;
            case GpsStatus.GPS_EVENT_FIRST_FIX:
            // First Fix...
            break ;
            case GpsStatus.GPS_EVENT_STOPPED:
            // Stopped...
            break ;
            }
        }
    };

i want to test whether device is :

  • no change
  • new location
  • start_
  • no gps data

Can you explain the GPSs status with example??, thanks.

EDIT: guys, it very helpful so far, now i stuck with no change location: when user still stay on the same location then onLocationChange method will not fired am i wrong? so how can i test it in order to send to server? :)

0

2 Answers 2

2

Look at LocationManager, GPS status is about the GPS engine itself not location notifications and is not reliable on all platforms/devices even to determine if you have/had a fix.

Or alternatively an older but still relevant tutorial

0
1

When the onGpsStatusChanged() is called from the framework it means that there is a valid gps status update. Use getGpsStatus() to retrieve the latest GPS status updates.

public void onGpsStatusChanged(int event) {
        if (event == GpsStatus.GPS_EVENT_STARTED) {
            Log.d(TAG , "GPS event started ");

        } else if (event == GpsStatus.GPS_EVENT_STOPPED) {
            Log.d(TAG , "GPS event stopped ");

        } else if (event == GpsStatus.GPS_EVENT_FIRST_FIX) {

            GpsStatus gs = locationManager.getGpsStatus(null);

You can use the above snippet. Note that some of the data you want is in the GpsStatus structure.

The rest of the info you require like new location can be obtained from the onLocationChanged() callback.

4
  • what do u mean by valid gps status, u mean gps available??? if not valid means no gps ?? how about gps no change ? how to test it ?? thx
    – sayvortana
    Jul 20, 2011 at 5:31
  • No I mean a new GPS status is available. What is your definition of "no change"? : No location change? No status change?
    – Reno
    Jul 20, 2011 at 5:42
  • Reno: what i mean by no change is when the gps stay still no change so it means the same in that case it will not fire the onLocationChange method right? so i want to resend my current to the server where should i test it?
    – sayvortana
    Aug 15, 2011 at 2:49
  • It depends on the parameters of requestforlocationupdates(). If you mean "no position change", it depends on the mintime parameter. If you set it to 1000, onLocationChanged will be called every one second even if there is no change in location.
    – Reno
    Aug 15, 2011 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.