In my app I am using Android Location Manager API and I have a requirement of identifying whether the location coordinates are from normal Location Manager or if they are from Fake(Mock) Location provider. I used location.isFromMockProvider(). Once I turn on the fake location providing app, isFromMockProvider() method returns me true. And after that it does not matter if I turn, fake location providing app, on or off isFromMockProvider() method always returns true.
I found that once FakeGPS app, once triggered, overrides the location manager coordinates and once I stop the FakeGPS app, the Location Manager does not start collecting correct coordinates.
Is there something I am missing.
Disappointed with no response but I am glad that I got it working :)
Posting the resolution as it might help someone else.
Once the FakeGPS app starts mocking location, it stops my app's Location manager.
Now even if I stop the FakeGPS app mocking service, the location manager of my app won't trigger back.
I have to detect the event and restart the location manager of my app, after removing any test provider and clearing test locations.
just resetting and removing test location should help
String t = LocationManager.GPS_PROVIDER;
locationManager.clearTestProviderEnabled(t);
locationManager.clearTestProviderLocation(t);
locationManager.clearTestProviderStatus(t);
locationManager.removeTestProvider(t);
Related
In my app I am using FusedLocationProviderClient to get user location every time he enters the app by mFusedLocationClient.getLastLocation().addOnCompleteListener().But sometimes result is null,I am using <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> in manifest.How can I get user location even if it not so correct?Because the logic of app depends on that location,I don't need to show it on map or smth like that,just get the location.Thx in advance
Don't use getLastLocation(). There is always a chance to have it return null if it doesn't have a location currently.. Use requestUpdates or requestSingleUpdates- when the callback for those is called the location is guaranteed to be non-null. getLastLocation() should only be used as an optimization to improve speed, it cannot be relied on.
Follow the following example and your app is guaranteed to work as you wish. I have recently used this code and it is working like a charm.
Only thing you should know is that for the location updates to actually work ( to get real latitude and longitude values) you should enable "google play services". There may be several ways to do this but perhaps the simplest of all is to open "settings" on your device and probably somewhere under "security" or "permissions" (depending on your android distribution) find "google play services" and give it the permission it needs.
https://github.com/googlesamples/android-play-location/tree/master/LocationUpdates
I want to set mock location for specific app only. So far, what I have understood is, if I set GPS provider with some mock location then, all apps accessing location through GPS will receive mocked location. Can it be made app specific? (means only specific app should see mocked location, all other apps will see true location.) If yes , how?
I am working on app. When user click on button he will get current location using GPS.
All is working fine but one problem.
Problem
There might be some location where gps will not work...like closed area...and gps can not find location...at that time it will return previously know location...Previously known location may be too older or wrong.
so at that time I want no location found instead of last location.
Is there any way to check if fix is available or not ?
I've tried to run Geofences sample and I've got little confunsed regarding to how it works.
Prior to go on, I've studied the new APIs and wached this video:
http://www.youtube.com/watch?v=Bte_GHuxUGc&list=WLRNCZT9Eq_HTG5jIEFxMpdqoXZBNalekx
So I jumped coding it. I thought that this API would manage the GPS position's captures automatically, in order to get my position.
So at this point raises my doubt. I've only got notified within a geofence, if I turnned my google map app on so my device starts capturing my location thru GPS.
So, what should I do to have "my app" forcing GPS use ?
I appreciate your help.
Best Regards,
Marlus
I would like to check if Location Client is able to provide any location. Is there any way to do so, apart from calling normal location system service?
The accepted answer was correct at the time. But in recent times things have changed with the availability of the SettingsApi It allows you to check if the location services are available on the device and there is a complete example provided by google on github that shows how to use this API. The sample code will prompt the user to enable location if it's switched off.
AFAIK, there is no method to check availability.
Possible Reason:
LocationClient uses fused API which gives location with appropriate combination of GPS,WiFi,Cell,Sensors (according to the Priority you have set for retrieving location).
Reference:
Fused API - Beyond the blue dot
Alternate Solution:
You already know it.you can check availability of provider by using location system service and LocationManager