How can I force Network Location? - android

I want to turn on the Network Location ("Wireless networks" - Location determined by Wi-fi and/or mobile networks). Is this possible?
In my application, I can force 3g connection (only in Android 2.3+, I have problems with WRITE_SECURE_SETTINGS on Android 2.2) and GPS Location.
Thanks,

You can do it via root methods if you must, however, I would recommend prompting the user in most cases.
See Android get location or prompt to enable location service if disabled for prompting. I'm really not sure about the root method but it is documented somewhere on the XDA-Forums I'm sure.

Related

How to programmatically turn on GPS on Android

I have survey some article on stackoverflow.
It seems android version above 4.0 is not able to turn on/off GPS programmatically.
Is there anything changed now? Or is this still not possible?
You can't turn it on/off programatically due to security reasons. According to Change location settings docs:
If your app needs to request location or receive permission updates, the device needs to enable the appropriate system settings, such as GPS or Wi-Fi scanning. Rather than directly enabling services such as the device's GPS, your app specifies the required level of accuracy/power consumption and desired update interval, and the device automatically makes the appropriate changes to system settings.
So, the best thing to do is, if the user has disabled the GPS, then for better UX you can show a prompt and redirect the user to the Location activity like this:
MainActivity.Instance.StartActivity(new Intent(ActionLocationSourceSettings));
Where MainActivity.Instance is your current Activity.

Disabling Location permission on Android 6 seems to affect WiFi parameter queries

I have an Android application that accesses the device's location and then queries the WiFi parameters. Everything typically runs smoothly.
If I turn off the Location permission for the app (as I can do in Android 6) I no longer get the device's location (as is expected). However, I also get a modified WiFiInfo object when I try to query the WiFi parameters. In particular:
getScanResults() normally lists all of the networks available, but with Location turned off it only contains the network the device is connected to.
If I look at the capabilities of the network that is found, the string is empty. Normally it contains information such as the wireless encryption information.
Has anyone else seen this? I've verified it using the same code with the Location permission turned on/off on 2 different devices. Any idea on what's happening?
Update: On further review, I was wrong when I said that getScanResults() returns information about the AP that the device us connected to. It in fact returns an empty list. This would support the idea that Google doesn't want us to have any information about the local APs if Location permission is denied.
WiFi-based location is basically a lookup of WiFi access point information in a giant database of known APs and locations to discover where a device is. This is what services such as Google, SkyHook, and Apple use when you enable WiFi or network location.
I suspect Google is trying to prevent an application from accessing information from which location can be derived when location is disabled. They have previously blocked access to Google Play location services when location is disabled, but this does not prevent a device from doing a scan, collecting the same data that would be sent to Google, and sending this data to a different service to discover location.

How to use android network location without Gapps?

Okay, so I removed all of Gapps from my android 4.1 phone.
My GPS can no longer be determined via wifi or towers.
(Is this because networklocation.apk depends on Gapps?)
Does anyone have a solution to enable network location without Gapps?

How to stop fake locations using LocationClient on Android

I'm working on a GPS game, similar to geocaching, which requires the devices accurate GPS cordinates.
I am using LocationClient and not LocationManager.
Early in testing, a friend pointed out that the location can be faked using free apps on the play store. A bit of research shows that without root, these apps require Mock Location to be enabled. So I started with a simple check to see if mock location was enabled, and if it was then the app would not allow the user to play until it is disabled.
This got me thinking though, users who are rooted could still fake their location without having mock location enabled, however most of these apps still have the MOCK_LOCATION permission regardless if the device is rooted or not. So I used a method that detects any apps that require Mock Location. The problem is, even on my non rooted Note 3, there appears to be several pre-installed apps that require Mock Location for some reason, which then prevents game play. So this solution wont work.
Is there any other way to check if a location might be faked using LocationClient?
In API 18+ you can use Location.isFromMockProvider to check if a particular location is mocked. This flag will be set to true if an app is providing mocked (fake) locations or if you are using a mock provider in your own app.
Of course, rooted phones can bypass this.
In your device, go to settings >> developer options >> allow mock locations
This option must be checked in you device that's why you are getting mock location updates. To stop receiving just uncheck it.
In your code, you can also set mLocationClinet.setMockMode(false); in your onCreate() method of Location tracking activity.
I hope it works :)

Using Android internal API to turn on GPS

Is there any hidden (internal) API function for turning on/off the GPS? Is it a valid solution (legally and safely) to use android internal API's? If it is not valid, how can I obtain a license/signature for using those API's?
I have already tried the methods using SDK/NDK and I understood that it is not possible to turn GPS on with the SDK/NDK (I know that we can bring up the settings screen). I want to know whether there is any hidden/internal API's for doing that. Also I am not interested in using any vulnerabilities in Android as a solution.
You need root privileges. Mandatory. Period.
And yes there is API to enable/disable GPS. But the application must receive SuperAdmin privileges. To obtain it either root or custom ROM required.
Sample: https://github.com/sms2000/GPSToggler
There is no hidden API for controlling the GPS. There is no valid solution.
(Like you mentioned), the correct thing to do is ask the user to turn it on. If an app could override the users option, there would be no point in it being an option and this would be a huge security rick.
If the user chooses to keep the GPS off then your apps should do the same thing it would do if the GPS was on but couldn't get a lock. Not respecting their wished to keep it off would be malicious even if you don't plan on doing anything morally wrong with the data.
If you have some client that wants their employees to not be able to turn off the GPS, then you need to give them phones with custom roms.
If you are trying to make a security app that reports location you can use wifi location and last known location too in addition to GPS.

Categories

Resources