"Unable to resolve host" error with Google Drive API - android

I am using Google Drive REST API to download 1.5 GB backup file using a foreground service. I found that after the file is downloaded partially, the following exception is generated by code:
Unable to resolve host "www.googleapis.com": No address associated with hostname
I am testing my application on Android 6.0 device. I have set the targetSdkVersion to 27.
I have following questions:
Is the device WIFI automatically tuned off when the device is kept idle for sometime? As I am using a foreground service, is it possible to have this problem?
If no, what can be the other causes for this issue?
I would appreciate any suggestions and thoughts on this topic. Thank you.

Starting from Android 6.0 (API level 23), App Standby defers background network activity for apps with which the user has not recently interacted. You can read the documentation about Optimize Doze and App Stanby of Android app.
If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services. Doze mode restricts to perform a Wi-Fi scans.
You can prevent the doze mode or standby mode of Android apps using foreground service by GcmTaskService.

Related

Android: how to execute service when nearby found some ble device

Right now I'm developing client application for Android that works with physical locks with our controllers. User can open lock via Bluetooth using this application (connection -> secure session creation -> sending some user key).
All works fine except one feature: opening lock when Android device screen is off.
I am using following approach:
Foreground service that periodically scans for nearby BLE devices and when scan is successful (nearby lock device found using BLE filters), application tries to connect and send lock key to lock device.
So, there are two problems:
Android kills foreground service in few minutes after screen off. After setting ignore battery optimization it works ok, however I can't find universal way to navigate user to those settings (because those settings are vendor specific, see https://dontkillmyapp.com/ and android open battery settings programically).
Background limits for BLE scanning are tricky.
I know one application that achieved same thing without foreground service: https://play.google.com/store/apps/details?id=eu.hoermann.ast.bluesecur, this application seems to work good in background without user interaction with battery usage optimization menu.
So, question is:
what is the best way to trigger background process (device screen is turned off) when nearby suitable BLE device available?
Your requirements perfectly describe the scenario of a companion app. Disadvantage: it is only available from Android 12 (API level 31) onwards.
I think you shoul add a wake lock with the service:
https://developer.android.com/training/scheduling/wakelock
https://developer.android.com/training/scheduling/wakelock#cpu

Android background services stop responding after ~1 day

I'm building an app that has two background/foreground services:
Sync with API on FCM data notification - high priority
Physical activity monitoring using Activity Transition API
This app is also ignoring battery optimization(on the exemption list).
If app is terminated and devices put to sleep, these services function properly for about 24 hours. After then they both just stop.
Devices has no battery saver mode enabled, it's unpluged from charging and the battery is at 90%. The device is Samsung with Android 11. App is not on the sleep/deepsleep list.
I can't get my head around why these services just drop out after those ~24 hours. Based on Android documentation, app with ignored battery optimization shouldn't Doze. And FCM message with high priority should wake the app from Standby. When this happens nothing really helps, I have tried manually disabling standby using adb and put the device on charger. The only thing that helps is relaunching the app.
Any help would be greatly appriciated.

Wake up android app via push notification while in doze without FCM

Greatings!
We are developing an android app with Xamarin that has to meet the following restrictions:
wifi yes, but no internet connection
no FCM/google play services (app should also work in China)
push messages from a Manager-SW (uses rabbitmq) need to arrive quickly after being send (< 1min) AND also when the device is in doze mode
no pulling mechanism
At the moment we are having a wifilock and a wakelock. The battery optimization for this app is turned off. This way messages always arrive even when the device goes to doze mode.. with some exceptions.
There are devices like the HUAWEI P20 that have their own battery save solution (App launch) --> app is not running although we have all the stuff above
Also this solution is not ideal considering battery usage.
I have looked into alternatvies like Pushy, but for me it seems they have problems with doze mode too.
Do you know any alternatives to FCM?
Is there any easy way to go around the Huawei stuff without the user having to change the settings manually?
Many thanks to all of you in advance!

Android Doze Mode - Bluetooth

My question is fairly simple. I would like to know what it is the best practice for my app so that it can be "Doze-proof". This is getting even more relevant as Android N will be applying Doze in more case scenario.
While reading Doze Documentation there is a part mentioning network access :
In Doze mode, the system attempts to conserve battery by restricting
apps' access to network and CPU-intensive services. It also prevents
apps from accessing the network and defers their jobs, syncs, and
standard alarms.
I believe Buetooth falls under Network Access, is that correct?
Since I do not own a Marshmallow (or Android N) enabled-device and since Emulator does not allow Bluetooth interaction I cannot really test my app behavior in Doze Mode.
Will Doze Mode kill any ongoing Bluetooth connexion? Does the same apply either for Bluetooth Classic and LE ? What about headsets with Bluetooth A2DP ?
My app must maintain this connection or else the core functionality will be broken.
Surely there is some kind of exceptions for such case where your device needs to be connected to a Bluetooth remote device for as long the user whishes too.
I know there exists a Doze Whitelist but it would seem it might not, in some cases, let the app behave as it would on a device below API 23.
Thank you for your help!
Looks like doze doesn't have any restriction on bluetooth per se but to do anything meaningful, you would need to keep the cpu on and wake locks are ignored in deeper doze.
If it's a core functionality of your app, you can try to ask users to whitelist your app. This can grant partial wake locks and keep the cpu on.
Foreground services are also exempted from any doze restrictions so that's another transparent way.

Android BLE disconnected when screen off (without charger)

It's working well on most Android devices.
Other device's screen gets locked after 1 minutes BLE device gets disconnected,if device without charger.
Thanks for any suggestions!
this might come from the Keep Wi-Fi on during sleep option (which might affect all radios) - as it seems this only exists in 8.0 but not in 8.1 (at least on the Pixel 2 XL, according to this article).
You might be having this problem because your app is not properly configured to handle Doze mode.
While there do not seem to be any restrictions on using BLE itself, doze mode might be messing with the control mechanism for your bluetooth connection (ex: a background service).
To see if this is the issue, you can whitelist your app manually via Settings > Battery > Battery Optimization and disabling optimization for your app.
Furthermore, as of Android 8.0, there are restrictions on background services when your app is not in the foreground. So, you may need to create a foreground service to handle the connection.

Categories

Resources