2

How am i able to Stop GPS from receiving new signals?

Just use:

if you initialize a LocationManager Object

mLocationManager_ = (LocationManager) mContext_.getSystemService(Context.LOCATION_SERVICE);

add a location listener, GPS is starting to a GPS-Lock,

mLocationListener_ = new MyLocationListener(mContext_);
mLocationManager_.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener_);

If this lock exists, you see the GPS Signal in your status bar, now, if you press Home, you see, the GPS is still online, because your App is still having and trying to continue your GPS lock,

so use

Main.mLocationManager_.removeUpdates(this);

to stop your App from receiving new location updates.

tshepang
  • 12,111
  • 21
  • 91
  • 136
cV2
  • 5,229
  • 3
  • 43
  • 53
  • What is Main here. Is it application name or something else. Pls tell me –  May 23 '12 at 10:13
  • hey, mLocationManager_ is a static variable in my case, so it's just the Way i access it. It's just a LocationManager variable (you dont need it) – cV2 May 23 '12 at 12:18
  • Thank u. I have one doubt. I want to hide the gps icon from the task bar when I stop the service of my application through menu item "disable". –  May 23 '12 at 12:40
  • For this I have written the following code public void onDestroy() { mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); mlocListener = new MyLocationListener(); mlocManager.removeUpdates(mlocListener); } But the icon is displaying on the taskbar. Plz help me. In some links, somebody told –  May 23 '12 at 12:41
  • that u have to root ur mobile. Is it necessary "root a mobile" to disable gps icon on the task bar.Pls help me. Its urgent for me. Thank u in andvance –  May 23 '12 at 12:43
  • 1
    no, no root is necessary, if your application is checking location via GPS this icon is shown, so there may be some problems with "removeUpdates.." go it through with debugger... removeUpdates normally removes all updates (GPS requests) and the icon should disappear by default.. good luck any further question, dont hesitate to ask, or post some code – cV2 May 23 '12 at 13:12
  • thank u. Here I have one small doubt i.e we can get the location either GPS or network. If I disable the Gps then automatically the location may come by using network. But here my requirement is whenever I click the "Enable" menu item then only the location has to display. I did not get the solution for disabling the icon on the task bar. Is my code is correct or not which i have sent above. –  May 24 '12 at 04:13
  • can i send the code to u. Pls give me ur mail id. –  May 24 '12 at 04:30
  • you can decide if you use GPS or NETWORK location service, please post your code here, so everyone has some benefit :) – cV2 May 24 '12 at 07:04
  • Thanks a lot. I got the solution for disabling the gps icon on the task bar when i click the disable menu.Thank you again for great suggessions. –  May 24 '12 at 08:05
  • Is it possible to disable the network in our android mobile through programming. Because I don't want the latitude and longitude through network. Thank u in advance. –  May 24 '12 at 08:08
  • yes, as described above, with: mLocationManager_.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener_); you look/wait for a gps connection lookup, while with mLocationManager_.requestLocationUpdates(LocationManager. NETWORK_PROVIDER, 0, 0, mLocationListener_); you check for network location, this is it :) good luck and never mind :) you are welcome :) – cV2 May 30 '12 at 18:19

0 Answers0