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

  • Home
  • SEARCH
  • 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 8879367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:56:03+00:00 2026-06-14T19:56:03+00:00

I am creating an app which uses GPS. For the first time in onCreate()

  • 0

I am creating an app which uses GPS. For the first time in onCreate() I am checking whether the GPS is enabled or not. And if its not enabled then I am sending the user to the setting menu to set the GPS enabled.

Once the GPS is enabled then I starts executing my stuff. But if in between the user stops the GPS scrolling on Notification manager then how would I know this?

Because my method executed only once when the GPS is not enabled. After that its not getting executed when it is disabled again.

I just want to know whenever in between the work the GPS is disabled by the user. Just this information is required.

Here is my code.

class LocationFinderService extends Service{

    boolean gps_enabled;
    LocationManager locationManager;
    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        if(!isGpsEnabled())
        {
            startGpsForLocation();
            stopSelf();
        }

    }
    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    public boolean isGpsEnabled()
    {
        gps_enabled = (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)&& locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
        Log.i("Log", "Gps:  "+gps_enabled);
        return gps_enabled;
    }

    public void startGpsForLocation()
    {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ;
        startActivity(intent);
        Toast.makeText(this, "Please start the GPS", Toast.LENGTH_LONG).show();
    }
}

I am calling this service on the button click of the Activity class.

Any help would be appreciated.

  • 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-06-14T19:56:04+00:00Added an answer on June 14, 2026 at 7:56 pm
            lmGps.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,gpsLocationListener);
            lmGps.addGpsStatusListener(gpsStatusListener);
    

    gpsLocationListner is

    LocationListener gpsLocationListener=new LocationListener(){
            public void onLocationChanged(Location location){
                dGpsLat=location.getLatitude();
                dGpsLng=location.getLongitude();
    
    
            dLat=dGpsLat;
            dLng=dGpsLng;
            try{
            SaveLocation();
        }
            catch (Exception e) {
                sResponse=e.toString();
                return;
            }
        }
        public void onStatusChanged(String provider,int status,Bundle extras){}
        public void onProviderEnabled(String provider){}
        public void onProviderDisabled(String provider){}
    };
    

    gpsStatusListener

    GpsStatus.Listener gpsStatusListener=new GpsStatus.Listener(){
            @Override
            public void onGpsStatusChanged(int event){
                if(event==GpsStatus.GPS_EVENT_SATELLITE_STATUS){
                    try{
                        GpsStatus status=lmGps.getGpsStatus(null);
                        sats=status.getSatellites();
                        Iterator satI=sats.iterator();
    
                        int count=0;
                        while(satI.hasNext()){
                            GpsSatellite gpssatellite=(GpsSatellite) satI.next();
                            if(gpssatellite.usedInFix()){
                                count++;
                            }
                        }
                        iSalelliteCount=count;
                    }
                    catch(Exception ex){}
                }
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

long time reader, first time asker... I am making a music app which uses
I am creating a web app which uses jQuery to authenticate: $.ajax({ url: /session/create?format=json,
I have started creating an app which uses a core data stack at the
I'm creating an app which uses a Data Access Object class to load values
I am creating an app which uses Core Data. I have a flip-side in
I am creating an RCP app which uses a host of third-party plugins. Some
I'm creating app which uses very large amount of memory. When I finish computation
I am creating a phonegap app which uses google maps to show directions and
I'm creating an iOS app which uses django as my backend. I need to
I am creating a WPF Smart Client app which uses WCF and NHibernate on

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.