aandroidtest
aandroidtest

Reputation: 1503

Retrieving GPS coordinates when location services are not enabled

Assuming the device's "Use Wireless networks" and "Use GPS satellites" settings under Location is not enabled, is it possible to still retrieve the location coordinates.

Currently, the best is to redirect the user to the settings page is not enabled. I find this disruptive as needs to navigate away from the app.

If i am not mistaken, you can enable the settings programmatically (Am I correct?).

I don't need the exact coordinates, is it possible to get the cell tower ID without the settings enabled?

Upvotes: 0

Views: 1510

Answers (5)

hd1
hd1

Reputation: 34657

Deep dive into location has a set of best practices for Android's LocationManager. You do not need the GPS to be activated -- in many cases, the mobile network itself gives a pretty good approximation of the location without taking up extra battery.

Upvotes: 0

alshapton
alshapton

Reputation: 568

Agreed - in earlier versions of android, you could programatically turn on the GPS - but more recent versions do not allow this to happen. As Anup states - the common acceptable practice now is to redirect the user to the options page and allow the user to select the type and nature of GPS that the application is allowed to use.

Dont forget , you dont need to "leave the app" to get the user to turn on GPS, you can send them to the settings yourself:

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

This will then come back to your app where it left off - giveing the use a seamless experience, and one which they will be familiar with from other android apps.

Upvotes: 0

Rana Shouman
Rana Shouman

Reputation: 106

switching on Location settings programmatically without the users consent is impossible let alone bad practice. You can prompt the user and direct him to switch on location settings or if you program tracks the progress of the device user, you can have the program send an alert of some sort telling them that the Location setting is off.

Upvotes: 0

Anup Cowkur
Anup Cowkur

Reputation: 20563

No. If the user doesn't want to give you his location, There is no way you can get his location.

This is a security measure and it exists for good reasons. If you try to subvert this, your app will be considered malicious.

Redirecting the user to the settings page is the best option.

Upvotes: 1

Daniel Scocco
Daniel Scocco

Reputation: 7266

Setting anything programatically without asking the user first is bad practice.

What you could do is, in case you can't get a location, ask the user to turn GPS on or tell him your app won't be able to work and will close.

Upvotes: 0

Related Questions