Bug? GPS won't turn off

NeoTechni

Well-Known Member
Licensed User
Longtime User
I call GPS.stop on activity_pause, yet I catch the location services indicator in the menu bar, and my app drains a ton of power. Is there a different way to turn it off that I'm missing?
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Some times GPS takes too long to turn on, so I reinitialize it every minute in the event it receieves no data. Plus the user can retrigger the initialization with a button press
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
It can take the GPS 1 - 2 minutes to find 4 satellites. I don't think that initializing it again will make it faster.

You must call Stop before you initialize the GPS again.

I'll remove the timer, and try stopping it before every init. Thank you.
 

ttsolution

Member
Licensed User
Longtime User
Dear all,

I searched in Internet that below Java code can turn GPS ON/OFF. How can we transfer to B4A ? I have tested with TurnGPS, Toggle library but not sucess. It is ok with 3G but not sucess with GPS.

JAVA CODE
publicvoid turnGPSOn(){Intent intent =newIntent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled",true);this.ctx.sendBroadcast(intent);

String provider =Settings.Secure.getString(ctx.getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED);if(!provider.contains("gps")){//if gps is disabledfinalIntent poke =newIntent();
poke.setClassName("com.android.settings","com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));this.ctx.sendBroadcast(poke);


}}// automatic turn off the gpspublicvoid turnGPSOff(){String provider =Settings.Secure.getString(ctx.getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED);if(provider.contains("gps")){//if gps is enabledfinalIntent poke =newIntent();
poke.setClassName("com.android.settings","com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));this.ctx.sendBroadcast(poke);}}

Regards,

Jonh
 
Top