Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

start Android gps service

Tags:

android

is there any way to turn on gps service through code?

like image 920
Andy Avatar asked Dec 21 '10 10:12

Andy


People also ask

How do I turn on Google location services?

Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.


2 Answers

There's a good example on HelloAndroid

Check for the GPS

LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,1.0f, this);
boolean isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);

If isGPS is false open the settings

startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);

Don't forget to check the GPS is enabled when the user returns, they might not enable it.

like image 176
Rob Avatar answered Oct 02 '22 19:10

Rob


No.

Turning on GPS is a user's choice. It would be unethical to force it.

like image 34
darioo Avatar answered Oct 02 '22 19:10

darioo