I would like to get the location of a smartphone (service runs in background) if location is turned off. Is there a way to automatically activate the Location service if it is turned off? For locating the user the FusedLocationProvider is used.
I guess that there is no chance to get the location by WiFi, GPS or cell towers if the location sensor is turned off.
The answer is you can't turn on the location automatically. The user has to give permission that's why it comes under PROTECTION_DANGEROUS.
Related
I'm trying to develop an android application which can acquire GPS location without using Internet and even network location using SIM. Actually, SIM will be inserted in phone and i know that location upto 500m accurate can be acquired through it. But in case of no SIM signals in the area, is it possible to acquire location?
Yes, you can use GPS without any external data connection because signals from the GPS satellites are receive-only.
On a device, the permission setting is known as device-only location mode:
Device only
This mode uses only GPS. It doesn’t use Google's Location service to provide location information. It can estimate your device's location slower and use more battery.
Yes You can get the coordinates but for using map services you need internet.The only thing is your GPS will take a bit longer to lock your location on a cold start, and it might not be quite as accurate.
It's a aGPS (Assisted GPS), and get's part of the location information from the data network (If available) on cold start, then fine-tunes the location further than what a GPS alone can do.
Shouldn't be an issue however, really. Just turn your GPS on a little sooner (Like while getting ready to leave, not waiting until you are in your car).
Yes. If you use the Location Manager, set the Provider to LocationManager.GPS_PROVIDER. If you use Google Play Services, it should work automatically.
I'm using Google Play Services to get the current location of the user. Basically I use the codes at http://www.androidhive.info/2015/02/android-location-api-using-google-play-services/ to get the location. So herein lies my problem:
1) I can get the current user location on my Xperia Mini (Running ICS) without any problem. If I didn't enable the GPS, the location that I'd receive (expectedly) isn't that accurate, but I will still get it. And if I enable the GPS, I would (again, expectedly) receive a much more accurate location.
2) But when I tried running my app on my Zenfone C (Running KitKat), if I didn't enable location, I would never get any location. getLastLocation and onLocationChanged will always return null. Only after I enable location, I'd get the location. But after I disable location and tried to getLastLocation again, it will again, return null.
The situation that occurs on my Zenfone C puzzles me, because from my understanding, even if we didn't enable location/GPS, we would still be able to get the current location from the mobile network or wifi triangulation, because that's what happening with my Xperia Mini, and I thought that should be the standard for all Android devices? Or is the enable location on/off on some Android devices have some other meaning? Perhaps on some device, when location is turned off, there's no way we can get the location. Can anyone here shed some light on this?
Thanks
There's no way for the device to get new locations once the location mode is set to off, but it's possible that the one device had a cached location from when the location mode was set to on.
Network location (Power saving mode on some Android versions) needs to be enabled to get a location from mobile data or WiFi. Note that if you use the toggle button, it enables/disables both network location and GPS (High Accuracy mode). You can use the sub-modes to enable only one location mode (Power Saving for Network only, or GPS only).
For more info, take a look at the screenshots in this answer.
The answer to the question here provides the method to activate the location if it has been turned off.
Now, Android has three location settings currently:
High Accuracy: Uses GPS, WiFi and cellular network to get the location.
Battery Saving: Uses cellular networks and WiFi to determine the location.
Device only: Uses GPS to determine the users location.
Checking the location status using the line:
gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
I redirect the user to the Activity where he can switch on the location. Now if the user turns on the location in the battery saving mode, will I get the location.
Also, for the redirection I do:
context.startActivity(myIntent)
Is there anyway to call startActivityForResult() here to verify if the user has turned on the location and depending on that redirect the user to different activities?
In Battery Saving mode GPS is OFF, so through GPS you will not get the location. but in Battery saving mode you can use WIFI and Mobile networks to determine the location
My android app relies on location. However the FusedLocationProvider which I use for this as abstraction layer so that I do not have to worry about what LocationProvider to use, behaves unexpectedly.
Scenario:
User opens app. I check for the availability of the providers and open the location settings page. The user enables "Access to my location" and both GPS and Wi-Fi location. When the user returns to the app I receive no location updates.
When I leave GPS turned off and only allow Wi-Fi in the System settings, I get an updated location.
I tried the priorities PRIORITY_LOW_POWER and PRIORITY_BALANCED_POWER_ACCURACY which both did not give me a location update when GPS was turned off.
How does it come, that the detection of the location works with GPS turned off and doesn't when it is turned on? Does that make any sense?
The location I obtain, when GPS is turned off is accurate enough for what the app is doing. If the device has had LocationServices turned on for a longer periods of time (Including the phone being outside) I receive Location Updates even with GPS turned on.
Does someone have an explanation for this / know how to solve this?
Phone: Nexus 4, Android 4.4.2, Google Play Services 4.3.25 (1117461-036)
Goal:
I want to record GPS positions via the fused location provider.
The code works the "standard" way": using location client and location request, registering for updates in onConnected with the pending intent starting intent service for handling of each location update received.
The LocationRequest.PRIORITY_HIGH_ACCURACY accuracy is used.
The problem is this
I turn on Location in settings (I see Mode: high accuracy there), and then press the button to start recording of positions
However, no updates are received.
Then, I turn on WiFi and suddenly, the updates are received.
The strange part is that I don't have to connect to any WiFi network. It is enough that I just turn WiFi on in the settings
Now, when I turn off the WiFi completely, and then start recording again, I get the updates as expected
It seems that even when using the high accuracy, the fused location provider isn't using GPS provider until WiFi is on.
Did anyone experience the same behaviour?