Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3397822
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:34:29+00:00 2026-05-18T04:34:29+00:00

I am making a application that uses the GPS receiver. The application will work

  • 0

I am making a application that uses the GPS receiver. The application will work on all versions starting from 1.6. I have a satellite Icon in which I tell the users the current status:

  • if icon is red – gps disabled
  • if icon is orange – gps is enabled and trying to fix on the satellites
  • if icon is green – gps is fixed and running fine.

After reading around here, I’ve found that some events for onLocationChanged trigger on 1.6 version but not later, so taking the advice I implemented a GPS listener. I have some really weird behavior as the status of the icon gets messed out. For instance I enable GPS and gets orange… after a fix get’s green.. after a few seconds gets read after a second orange and so on…

Here is the code I use. Please suggest what to change

public class TrackExecutionActivity extends Activity{

protected static final long GPS_UPDATE_TIME_INTERVAL=3000;  //millis
protected static final float GPS_UPDATE_DISTANCE_INTERVAL=0; //meters
private LocationManager mlocManager;
private MyGPSListener mGpsListener;
private LocationListener mlocListener; 

@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.trackexecution);

        imgGpsState = (ImageView)findViewById(R.id.imgGpsState);
        mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        mlocListener = new MyLocationListener();
        mGpsListener = new MyGPSListener();
}

private class MyGPSListener implements GpsStatus.Listener {
        public void onGpsStatusChanged(int event) {
            boolean isGPSFix = false;
            switch (event) {
                case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
                    if (mLastLocation != null)
                        isGPSFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < GPS_UPDATE_TIME_INTERVAL * 2;

                    if (isGPSFix) { // A fix has been acquired.
                        imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_green));
                    } else { // The fix has been lost.
                        imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_orange));
                    }

                    break;

                case GpsStatus.GPS_EVENT_FIRST_FIX:
                    imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_green));
                    break;
                case GpsStatus.GPS_EVENT_STARTED:
                    imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_orange));
                    break;
                case GpsStatus.GPS_EVENT_STOPPED:
                    imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_red));
                    break;
            }
        }
    }

public class MyLocationListener implements LocationListener
    {
        public void onLocationChanged(Location location)
        {
            if (location != null) {
                       mLastLocationMillis = SystemClock.elapsedRealtime();
            // do some things here
                     mLastLocation = location;

        }
        public void onProviderDisabled(String provider) 
        { 
            imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_red));
        } 

        public void onProviderEnabled(String provider) 
        { 
            imgGpsState.setImageDrawable(ctx.getResources().getDrawable(R.drawable.gps_on_orange));
        } 

        //this doesn't trigger on Android 2.x users say
        public void onStatusChanged(String provider, int status, Bundle extras) 
        { 
        }
        }
        }

 @Override
    protected void onResume() {
     if(mlocManager != null) {
         if (mGpsListener == null)
         {
            mGpsListener = new MyGPSListener();
         }

         if (mlocListener == null)
         {
            mlocListener = new MyLocationListener();
         }

        mlocManager.addGpsStatusListener(mGpsListener);
        mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_UPDATE_TIME_INTERVAL, GPS_UPDATE_DISTANCE_INTERVAL, mlocListener);
      }
       super.onResume();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:34:30+00:00Added an answer on May 18, 2026 at 4:34 am

    change this:

    isGPSFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < GPS_UPDATE_TIME_INTERVAL * 2;
    

    your are setting a boolean with non boolean values.. hence the weird icon behavior during gps fixes you need to set that isGPSfix boolean somewhere.. for case of hasGPSfix or doesnothaveGPSfix..

    You might have meant:

    if ((SystemClock.elapsedRealtime() - mLastLocationMillis) < GPS_UPDATE_TIME_INTERVAL * 2) {
        isGPSFIX = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im making an application that uses of API-threads in C, The program takes N-files
Question 1 I want to make IPhone application that uses OpenID for authentication. I
I'm writing an application that uses the PowerPoint interop library for Office 2010. It's
Suppose you have an application that consists of two layers: A: A data layer
I am making a download and installing application that must run multiple times at
I am building an applicaton in Java that will have some updates over time.
So, I have this new project. My company uses the SalesForce.com cloud to store
In order to ensure we have the correct routes for various vpn connections, we
I'm having a really odd issue and maybe one of you can shed some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.