Andy
Andy

Reputation: 5379

start Android gps service

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

Upvotes: 6

Views: 14906

Answers (2)

Rob
Rob

Reputation: 7099

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.

Upvotes: 17

darioo
darioo

Reputation: 47183

No.

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

Upvotes: 7

Related Questions