Extension with Rush. Keep the app running. Doze mode. Service. Notification. Source code

@Anke

An app that is whitelisted can use the network (in my extension Web.Url) and hold partial wake locks during Doze (MediaPlayer.setLooping running).

the weird thing is that s = s + 1 doesn't work for you

From this link:

I would like to understand if it is really possible to prevent Doze (completely) without a (Foreground) Service.

It works for some time (which cannot be precisely predicted) and then slows down and then stops completely. I had the same behavior with streaming (radio) apps. After a while, ignoring the battery optimization will no longer be effective and the network connection, CPU, timer etc. will be throttled or terminated. I tested this on my Galaxy Note8, S8 (Android 9).

This problem does not appear on some other test devices. But Samsung devices are still very common, so I needed a general solution. And I found this (as I said) with the Foreground service.

I'd really like to understand how it works.

So which service of the following do your extension use?

grafik

@Anke
It is not a Foreground service because it does not use startForeground, nor does it use "android.permission.FOREGROUND_SERVICE".

It also needs the help of the MediaPlayer, the old idea, to continue working, this should not be needed by a "normal" Service, so the code indicated on the web of tutoril is more of a service workaround.

Here's an example from Foreground, although I'm afraid it doesn't work the way we want it either.

2 Likes

9.- Testing with Bluetooth HC-06.

ServicioBluetooth.aia (106.1 KB)

  • I have only tested it on a Xiaomi with Android 9. It works, that is, it maintains the connection even with the screen turned off.
  • Arduino sends by Bluetooth 1 2 3 4 5 6 7 8...
  • App receives those numbers and shows them on the screen (and in Notification every 10)

bluetooth_Ser

#include <SoftwareSerial.h>
SoftwareSerial BT(2,3);

int k = 0;
String kString = "0";

void setup(){
 BT.begin(9600);
 Serial.begin(9600);
}
 
void loop(){
  k = k + 1;
  Serial.println(k);
  kString = (String) k + '\n';
  BT.write(kString.c_str());
  delay(1000);
}

(TODO, check battery consumption in hours.)

3 Likes

Thanks for the explanation.
I checked whether a streaming app was also running in the background (idle mode). And it works.

I will check later whether the ExoPlayer also works in Kodular with it. If so, it would be great. See here:

The question that remains is whether it will also work without notification?

10.- A mobile sends information to another that is with the black screen.

ServicioCuenta.aia (109.0 KB)

  • We install the application on a mobile, I'll call it BLACK DEVICE.

  • Click on "Start", then on "TurnOffDozemode", then on "Check if is Ignoring Battery Optimization" and on "Minimize this Screen".

  • We will observe that approximately every second counts one unit.

  • Now we close the screen, that is, we press the button of the mobile to put it with a black screen, in the sleeping state. So we leave it for 5 ... 10 ... 20 minutes.

  • In another mobile, I will call it WHITE DEVICE, we load the same application, in this we can do it with the MIT COMPANION or installed.

  • In this mobile we only press the last button "Send random number", every so often we press this button.

  • By pressing this button a random number will be sent to CloudDB, this same mobile will receive it and also the BLACK DEVICE, this will speak the number.

  • If the system works, we can leave the BLACK DEVICE mobile for a long time with a black screen and you will always receive the number sent by the WHITE DEVICE.

  • I have only tested it on a Xiaomi with Android 9. (Battery consumption with this app: 2.5 % / hour)

3 Likes

file "servicio.aia" รจ Free?

File servicio.aia is free.

This extension is free : com.kio4.servicio.aix

Extension com.kio4.servicio.aix is free.

1 Like

Hi Sorry, I would like to inform you that I have tried your .aia file, of this excellent extension, but everything works fine until I put the phone in the dark in suspension.

In fact, when I send a number randomly, the first time it is read remotely, regularly even with the app minimized and the mobile phone suspended, but the second time the number is no longer read remotely.

While, if I don't minimize the App, and put it on hold, everything is going well.

To me, it would be useful for it not only to be able to receive all the numbers that I send randomly but also for the summary to read them, even when the app is minimized, and the mobile phone in suspension.
It's possible? Because currently as I wrote it does not.

I am using two "Huawey p8 lite" phones

Hello @Angelo_D, I only tried this extension on Android 9, I put the source code in case someone wants to improve it. Thanks for trying it out.
Other extensions of this type:
Backgroung Task extension by @Kumaraswamy
or Ullis Roboter Seite/AI2 Keep Alive

1 Like

I tried it on a Galaxy Note8 (Android 9) and a Pixel 2XL (Android 11). The Pixel 2X was the transmitter.

The Note8 is particularly sensitive to Doze mode.
It works perfectly (even after 30 minutes in idle mode). I have 18 test devices running Android 4.x - 12. I will test it on other devices later. But I'm pretty sure it will work there too, though, because the critical device for Doze has always been the Galaxy Note8 and the Galaxy S8 (both Android 9).

I also have a Huawei P20 lite that I have to charge first. I'll test that later...

:+1: :clap:
Works perfectly!
And even without a Foreground service.

You can always surprise us.

4 Likes

As expected, it also works great on my Huawei P20 lite (after putting it in idle mode 20 minutes ago).

So tell us which devices and Android versions.
And are you absolutely sure you have turned off battery optimization?

It also works on a Pixel 4XL (Android 12).
I don't think it is necessary to do further tests.

Yes I have performed the battery optimization elimination.
But it still does not work, indicates only one number, ignoring subsequent ones.

This, with the app, minimized, and suspended display.

Everything else works great. Nice problem.

Just sending a repeated beep and a notification would be enough, even without a speaker reading the numbers.
In short, as is the case with any Android component: Email-Whatsapp-Messages.

As I already said, which device & Android version?