Retrieving GPS coordinates when location services are not enabled - android

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?

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.

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.

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.

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.

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.

Related

What to do when missing requirements to use app

In my android app there are certain requirements required in order to use the app (Internet access, GPS, etc.). Now I haven't really found anything dealing with this so I don't know if its a mute point or not. A user can leave your app at any time and turn things off/on on the phone. If I am checking to ensure that data access is available as well GPS in the app oncreate and onresume and just tell the user they need to switch it on, would that probably be enough? I'm thinking not. I'm thinking of redirecting the user to a new layout telling them what is missing and what needs to be done in order to use the app. This layout would also include a button for them to continue once settings are turned on. Is this a good idea or bad? I don't know if there is a better way of handling this or not so all input is appreciated. What do you do?
You might find some of your answers in Find Success on Google Play. If a user performs an action without satisfying all of the requirements, you could present a dialog explaining to the user what the requirements are and why they are necessary. You might also provide a link to redirect the user to the proper settings.
EDIT: The best practices in this situation are probably similar to Requesting Permissions at Run Time. Permissions Best Practices suggests something similar to what you are proposing, which is to show some sort of message or tutorial explaining to the user what is required and why, and then redirecting the user to the appropriate settings.
EDIT: One more example: That Android Documentation shows you how to use the Settings API to check which settings are enabled, and present the Location Settings dialog for the user to update their settings with a single tap. See Prompt the User to Change Location Settings

Prompting User to Enable GPS

Correct me if I am wrong:
1) You cannot programatically turn GPS On/Off on all versions of Android. Maybe some previous versions, and some hacks, but not on all devices. It simply is not allowed.
This leaves only two options:
1) Use new Google Play Services to prompt user to change these settings.
One issue with this is what if you just want to allow user to turn on GPS,
but not WIFI? The resolver will give them options to turn on both. How
can you just turn on one but not the other?
2) Send user to the settings application by firing off an Intent.
Now with 1) User must have current google play services installed.
If not they can be prompted to install it via standard GPS dialog.
Ok, now for 2) Sending user to settings application. I have the following problem:
When I fire off this intent, they not only get to change the Location/GPS Settings but they can also hit the little back button within Settings app, and adjust all settings. Is there any way to prevent this? Anyway to bring up the Location/GPS Settings without the inner back button? Thanks.
You cannot programatically turn GPS On/Off on all versions of Android. Maybe some previous versions, and some hacks, but not on all devices. It simply is not allowed.
Correct, for obvious privacy reasons.
When I fire off this intent, they not only get to change the GPS Settings but they can also hit the little back button within Settings app, and adjust all settings. Is there any way to prevent this?
No.

Is it possible to turn on Location Services forcefully?

I'm creating an app, that heavily relies on LocationServices.
For now I'm asking user to turn them on, and everything works fine.
However, when user clicks "No", the whole point of this app goes to hell.
I can spam user to turn location services on from my Service, however I find this solution extremely non-elegant.
Is there a way to turn this setting on programatically? I don't care for additional permissions or so.
I did my research and I only got what I already did - ask user to turn on location services with a dialog etc.
Is there a way to turn this setting on programatically?
Fortunately, no, for obvious privacy and security reasons, except perhaps on rooted devices.
However, when user clicks "No", the whole point of this app goes to hell.
Then advise the user once (per run of your UI) that your app cannot function, and the user should uninstall your app.
Bear in mind that many more permissions will have this same sort of user-recovable behavior with Android M.
You simply cant , if that was possible then you can easily gather locations which is for some unethical reasons could be sold ... so for security reasons its not possible at all .
you can always force the user to click yes by making a really useful and helpful application that the user simply want to try and cant click no because it wont function at all ...

Start Gps without any popup dialogue

I want to create a app which send users current location when user click on send button .
If gps is on than it will send the location, if gps is off then it automatically start the gps and then send location...
Manifest permissions is not a problem, problem is that it should not pop up dialogue to start gps when it is off..
Please help me, i really need help..
I want to know that is it possible?
If yes then a provide useful link or code or any kind of hint..
Thank you :)
There are a lot of other threads discussing this, and the general consensus is that it shouldn't be possible, even though on some versions there are exploits that allow it.
However, this doesn't seem to be ethical, since you are violating your users privacy by not allowing them to choose whether or not they want to share their location.
How can I enable or disable the GPS programmatically on Android?
Turning on and off GPS programmatically in android 4.0 and above?
ICS Android enable gps programmatically?

mark the particular setting from my App in android

I am getting problem in my app .where i need to mark the particular Settings I have used the following code:
startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
Its open the setting page but it does not mark the particular Entities.How could i get the automark option Could anybody help me out!!#Thanks
this is not possible, unless you have the rights and access the setting directly (not with an intent, but with the Settings class), and even though, I'm not sure you can.
What you can do is what google maps does. When your app starts, check if the gps is enabled, if it is not, display an alert notifying the user, with a button to quit the app, and a button to go to the settings screen. When the user comes back from Settings screen, test again.
If the action that you are trying to do was allowed then users would be very mad if some application would turn on their wireless connection or even worse the GPS sensor.
This change is available to change only by the user him self. So as mentioned the most you can do in case you need Internet connection or GPS sensor available is to present a user with the relevant message and fire an intent that will take them to the settings screen to change this setting them self.

Categories

Resources