Not retrieving GPS in background - android

I made an Android app (targetSdkVersion 27) that records the GPS track as we walk, once each minute. It is intended to work while the phone is in the backpack, screen off, app in background. It worked fine until I upgraded my phone to Android 10. Now it records only once in a while, rendering the app useless. I can even see the GPS icon disappearing when sending the app to the background with the middle button.
I guess the app is updating the GPS position only when the app is not in the foreground AND with the screen on. Then making a google search I find this: it seems Android 10 requires a special background location permission in the manifest file
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
I added the permission, but the problem persists (the location permission changed but I changed it back to "all the time"). Then I upgraded to targetSdkVersion 29 and AndroidX, and the problem persists. I don't know what else to try.

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.

How location changes in Android 11 will affect background requests?

I have an app that requests the user's location every 5 minutes and then maps their path.
To my understanding, with Android 11, Google changed how background location requests are handled. I have several questions about how this will affect my app:
Can I continue getting background location updates every 5 minutes?
If not, is there anything I can do to keep doing so?
When a new user downloads my app, what is the process of requesting background location permissions starting with Android 11?
I'm reading here that in Android 11:
On Android 11 (API level 30) and higher, however, the system dialog doesn't include the Allow all the time option. Instead, users must enable background location on a settings page, as shown in figure 3.
Does this mean that unless the user selects "Allow all the time", I won't ever be able to get the user's location in the background?
Thank you!
declare the ACCESS_BACKGROUND_LOCATION permission in your app
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

STEP_COUNTER and STEP_DETECTOR works with SDK 28, but not SDK 29?

I've made a service that regularly broadcasts counted steps from both the STEP_COUNTER and STEP_DETECTOR sensor. In one app I made it worked flawlessly, but after copying the exact same code to another project it stopped working. After hours of debugging, I figured out how to solve it. When I change the compileSdkVersion in the build.gradle to 28 it works fine, but changing it to 29 makes it stop working. Why is that?
As per the Privacy changes in Android 10 (which apply to apps that have a targetSdkVersion of 29 or higher):
Android 10 introduces the android.permission.ACTIVITY_RECOGNITION runtime permission for apps that need to detect the user's step count or classify the user's physical activity, such as walking, biking, or moving in a vehicle. This is designed to give users visibility of how device sensor data is used in Settings.
The only built-in sensors on the device that require you to declare this permission are the step counter and step detector sensors.
Therefore you must:
Add the android.permission.ACTIVITY_RECOGNITION to your app's manifest.
Request the permission at runtime and have the user grant that permission.

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.

Missing Google Services permissions in logcat

We have a weather app for Android that also provides a widget.
The widget displays the current time and weather for the current user location.
We update the widget clock every minute (via AlarmManager) if the display is active, the weather data at longer intervals. Sometimes the widget "freezes". We were able to track that down to the alarm for the next check not being set but don't have a clue why, yet.
Now we noticed the following warning in the device logs of an affected device:
03-12 10:15:44.803 771 4958 W ActivityManager: Permission Denial: opening provider com.google.android.gsf.gservices.GservicesProvider from ProcessRecord{41a4d028 25012:com.my.app/u0a88} (pid=25012, uid=10088) requires com.google.android.providers.gsf.permission.READ_GSERVICES or com.google.android.providers.gsf.permission.WRITE_GSERVICES
This starts to appear exactly at the time where the clock should have been updated. The message is then repeated several times until the ActivityManager terminates the process.
We use the Google Play Location Services to get the current (or last known) location of the user. I found references to a bug in version 4.2 of the services (here and https://stackoverflow.com/questions/22682538/when-to-use-read-gservices-permission) that could cause this error, but the device has version 6.7.76 installed.
One more thing to consider is that the device is running Cyanogenmod, though the stuck widget problem also happens on devices with "regular" Android.
Any hints what could cause this permission error are very much appreciated. Thanks!
Edit: The widget and app work fine on that and many other devices until the warning appears. Also the Google documentation is not mentioning that you need to get those permissions. In fact the only mention of those is here in this document according to the on site search, but no mention of READ_GSERVICES on the page itself.
The two permissions it is asking for:
<uses-permission android:name="com.google.android.providers.gsf.permisson.READ_GSERVICES"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.WRITE_GSERVICES"/>
Something to remember just because this issue was reported in Google Play Location Services in 4.2 does not mean it has been fixed. It may be worth looking through the Google bug reported to see if anyone has any issues. I found a few issues raised running much newer Google Play Services.
Upon doing a quick Google search myself it seems like the major problem phones are the Moto X and the Nexus 5. Which is rather interesting as they are both Android Open Source Project bugs (i.e phones running stock Android with no skin!)
Just a few questions:
Can you confirm what phone you have and which version of Android you
are running please?
Also what is your target SDK?
What version of play services are included in your APK?

Categories

Resources