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 981001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:28:21+00:00 2026-05-16T04:28:21+00:00

I’m starting to dip my toes into LocationManager. I’ve created a service which tracks

  • 0

I’m starting to dip my toes into LocationManager. I’ve created a service which tracks GPS location (interval is more than 60000ms) and updates my application with user location so they can find stuff nearby.

As I understand it, users can go into their preferences and disable GPS for a particular application.

I would essentially like to offer my users two modes. 1) GPS. 2) If GPS can not pull, device does not have a GPS chip, or GPS is turned off for my app, I would like to allow them to type in their zip code (or maybe switch to cell tower lookup).

The bolded text is what I’m interested in. How can I tell if the device does not have GPS? How can I tell if the user has disabled GPS for my application?

Side question: My service gets launched from my 2nd Activity. I call stopService in the onDestroy method of this Activity. If I back up to my 1st Activity and the 2nd Activity is destroyed, I still notice the GPS icon on my phone running. Is stopping the service sufficient? Or do I need to stop the LocationManager in the onDestroy of the service?

  • 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-16T04:28:21+00:00Added an answer on May 16, 2026 at 4:28 am

    If a user doesn’t have GPS activated, he could still have Wifi/Network activated as a location source in his phone settings, therefore you could use those data as well.

    You can always get the last known location of the GPS or Network via

    locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    

    and/or

    locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
    

    It holds the last known location by the device, which can be from your app or from any other app that has used GPS before.

    You can actually use two location managers with different providers: one with GPS_PROVIDER and another with NETWORK_PROVIDER.
    Gps is more accurate but usually only works outdoors under free sky why NETWORK_PROVIDER works indoors but is less accurate. Also, GPS might take a while until it gets a first fix after initialized (sometimes i.e. a minute or more), while the network get’s the location almost immediately.

    You should read this post, it’s very detailed and has sample code:
    What is the simplest and most robust way to get the user's current location on Android?

    Regarding the second question:
    before stopping the service, you should also unregister the location listener. You can do this onPause or onDestroy.

    locationManager.removeUpdates(baseLocationListener)
    

    or

    locationManager.removeAllUpdates()
    

    I think in your case using getLastKnowLocation() is fine.

    Nevertheless, if you want to explicitly know about the GPS status, you can implement a GPS Status Listener and then use something like below, which tells you if the GPS has any satellite fix or not – but as said, I don’t think this is really necessary.

    final class GpsStatusListener implements GpsStatus.Listener {
        public void onGpsStatusChanged(int i) {
    
            if (i==GpsStatus.GPS_EVENT_FIRST_FIX) {
                Log.d(AskTingTing.APP, "gpsx.fixed.");
                for (GpsSatellite sat:locationManager.getGpsStatus(null).getSatellites()) {
                    Log.d(AskTingTing.APP, "gpsx.GpsStatus.Sat.fixed: " + sat.usedInFix());
                }
            }
        }
    }
    

    Look at the link above for a good code sample.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I

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.