FusedLocationClient's requestLocationUpdates Callbacks available - android

I am using android location sample code "LocationUpdatesPendingIntent" link for requesting location updates even when the application is killed. It works very well in android 6, I don't turn on GPS in the device even then it starts showing me location but poor accuracy(that is acceptable). But in lollipop 5.1 it doesn't start and doesn't show any notification. Because it is getting null LAT and LONG. But it workes well even in lollipop 5.1 if I turn on GPS.
My Q is how to add some callback in:
mFusedLocationClient.requestLocationUpdates(mLocationRequest, getPendingIntent());
to check if it is able to get location LAT LONG or not. In lollipop case, it doesn't even fire broadcast.

Related

Issue with foreground service android 11 and 12

Any one know how get the location update every seconds. when my device on foreground or background mode.
I am working on Tracking app get the location in every seconds when he is waking on road or traveling whatever.
Actually my app working on version 10 not working on android 11 and 12.
Also searched on google don't found exact answer.
I used this permission:
Access background permission,
Access Coarse permission.
Access Fine Location.
OR Foreground services for notification
If any one know please let tell me
Thank you
in android 11 or higher the user has to go to app permissions and specifically give them permissions to always take the position in the background. This permission cannot be requested from the app. Only from the phone configuration.
To help protect user privacy, Android 11 (API level 30) introduces limitations to when a foreground service can access the device's location, camera, or microphone. When your app starts a foreground service while the app is running in the background, the foreground service has the following limitations:
Unless the user has granted the ACCESS_BACKGROUND_LOCATION permission to your app, the foreground service cannot access location.
The foreground service cannot access the microphone or camera.
Reference link : https://developer.android.com/guide/components/foreground-services#access-restrictions
you have to use the Foreground service for that and add a task in the Foreground service to get a location using geolocation or any other library.
steps to implement:
implement foreground service using link library::[1]: https://github.com/Raja0sama/rn-foreground-service.
add headless task using geolocation.
you will get the location after the app is removed from recent.

App crashing while disabling App location

I have a service ongoing which takes current location and sends it to the server.
While App is in the background with Service on, if I go to settings and turn off my App Location, the app is crashing I'm unable to able to catch the crash.
But if I kill the app and re-run it again the crash does not happen at that time.
It only happens when the app is in the background and at the same time app location permission is turned off.
Thanks & Regards
Syed
You could register for the LocationManager.PROVIDERS_CHANGED_ACTION in the BroadcastReceiver. When it is hit, you can check if the provider is still enabled and use that accordingly to prevent your app from crashing when someone revokes the location permission.
LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
boolean enabled = locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
Quoting
I mean if i have app in background and i turn my app location
permission off then if i open my app from background it crashes at
that time only. If i kill and open my app then it works fine. Im not
able to produce Exception/Error logs
The behavior you are observing is correct. You need to explicitly check for the Location Permission before registering/starting location update listener.

Mock coordinates Android Marshmallow

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);

Android app only updating location when other apps using location on Marshmallow

So I have an app that works flawlessly on many devices. The problem is on one specific phone with Android 6.
The location for our app only works when another app uses the GPS.
For example, starting our app, the GPS icon starts as if the GPS was active but location updates on the app do not appear or refresh. Then, we start Google Maps and only then locations on our app start getting refreshed. As soon as we close Google Maps, our locations stop being received.
I actually tested the app on another phone with Android 6 with no problems.
I think there might be some kind of issue with Google Play Services or with the new the permissions schema. Or maybe with BroadcastReceiver receiving the position updates.
Key information:
Our app es compiled for SDK 22 with Google API.
Google Play Services version on the phone with the issue is 8.4.92
The app uses this version of play services:
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services-location:7.+'
compile 'com.google.android.gms:play-services-maps:7.+'
compile 'com.google.android.gms:play-services-gcm:7.+'
All permissions are activated for our app on that phone.
The phone with the problem was working fine before it got updated to Android 6.0
We tested on another device with Android 6.0 and had no issues.
The phone is in a client in another continent so we don't have access to debugging or logs. No errors occur though because we would receive those on Fabric.io.
We use a Broadcast to dispatch new positions to a service and an activity so the problem might be there.
Im running out of options and tests.
Any ideas?
Thanks,
EDIT
The problem is that on that version of Android, getSpeed from Location is always 0.0, unless another app is using the location, then we get updates with the speed included.
This really sounds like a bug. Why would legacy apps not get the speed in the location? Assuming its because we use API 22.
On a side note, we use speed to filter out positions and stop updating location when the phone is standing still. Thats why we did not see location updates.
I guess we will have to calculate our own speed.

Never getting an Location (MvvmCross Location Plugin, Android)

edit: turns out it just takes waaay longer than the native implementation. :/
I'm trying to locate my position by using the mvvmcross location plugin.
Everything works fine as long as my device settings (Nexus 5) are set to "Energy saving", so no GPS will be used.
As soon as I set it to "High accuracy", I'll never get a GPS fix.
This happens regardless to MvxLocationAccuracy.
My current workaround is to check, whether MvxLocationAccuracy is set to "Coarse", and if so, set PowerRequirement to Power.Medium.
This will prevent Android from using GPS.
So my question is: what am I doing wrong? Why am I never getting an location, as soon as my device is using GPS?
I compared the mvvmcross plugin code to one of my native projects, which gets a high accuracy gps fix in a few seconds. Unfortunately I didn't find any errors.

Categories

Resources