Please disable the WakeLock to make shure that KeepAlive is the problem:
As I already said in my email to you, I used your test app and updated the new extension version there. The app crashes/freezes on Android 14 devices. I also removed all other extensions (WakeLock, UDPSender) - without success.
Unfortunately, we don't have the source code of the new extension yet to find out where the problem might be. (The new MediaNotification ext. seems to work fine on Android 14+.)
Done, disabled Wakelock blocks
The app stucks in the same way
I found a more in-depth guide to the Foreground service and realized that I hadn't made a necessary change.
You can download the extension, the current source code and a reduced example from this link: https://ullisroboterseite.de/_forDownload/Update-UrsAI2KeepAlive.zip
This are the modifications:
In the service declaration for the manifest parameter "foregroundServiceType" was added (file UrsAI2KeepAlive.java):
@UsesServices(services = {
@ServiceElement(name = "de.ullisroboterseite.ursai2keepalive.UrsService", enabled = "true", exported = "true", foregroundServiceType = "specialUse") })
In file UrsService.java making the service a foreground service parameter "foregroundServiceType" was added:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(notificationID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
} else {
startForeground(notificationID, notification);
}
Sorry, same issue
To find out what's going on, use logcat
Taifun
link to Explanation how to use it
The extension uses the log tag "KEEPALIVE".
You can use this command to get the log. Put it in a .bat file:
@echo off
echo clearing the log
echo.
@echo on
adb logcat -b all -c
cmd /k adb logcat KEEPALIVE:V *:S
Connect the device with USB to your PC, run the command from a DOS-BOX. On the phone you will be asked for a debug permission. Start the test APK.
You can download a version with a lot more log statements. https://ullisroboterseite.de/_forDownload/Update-UrsAI2KeepAlive.zip . These help to fix the critical program statements.
This version is OK (no errors)
I simply compiled the new .aia and installed the apk, without changing any settings.
Then I made little changes : I added a clock and TinyDB component, so now the app writes the current time on TinyDb every 10 seconds.
I started the service and turned off the screen.
After some minutes I turned on the screen and checked the TinyDB records.
When screen was off, the clock.Timer didn't write any record............
Then I tried enabling notification and disabling battery limitations.
No luck.
Extension Wakelock is not needed ?
I'm sorry, but I haven't fixed the problem. The extension will not work. I have only added instructions to prevent the crash and provide more information about the problem. This in reference to the previous posts regarding ADB.
Overnight I thought of a way to display the log messages on the cell phone screen. Unfortunately, I won't have time to take care of this again until this afternoon.
I have enhanced the extension so that the log can be output via events.
The sample project collects these events and displays them on the screen. The entire log can be sent to me by e-mail using the button. If everything would work you would get an output like the one in the picture. But probably (and hopefully) error messages will also appear.
https://ullisroboterseite.de/_forDownload/Update-UrsAI2KeepAlive.zip
I have received an answer. A permission was missing. I have added it.
Please try again. Note: For it to work, you must first press “Start Keep Alive Service”. Then the process is logged and displayed in the text field. The content of the text field can then be sent by e-mail.
https://ullisroboterseite.de/_forDownload/Update-UrsAI2KeepAlive.zip
Ok, now no errors
But I tried the TintyDB test again.
During screen off the clock.timer stopped and nothing wrote to TinyDB
This one: FOREGROUND_SERVICE_SPECIAL_USE
But why isn't this needed for your MediaNotification
extension?
As I said, add a Player and play a silent sound while the app is running to establish a wakelock. I checked it and it should work to keep the timer running also in idle mode.
I don't think it's working properly, at least not the FGS. But nobody notices because the app doesn't freeze.
Internally, an exception will probably be thrown that causes the service to crash, but not the main program.
After KeepAlive is working, I'll have to take another look at it.
I tried, but timer doesn't run with screen off, nor playing a video in loop.
Samsung A23 Android 14
It looks like I have a working version. Thank you for your patience and your help!
I will create and publish a usable version of the extension soon. Unfortunately I can't do it today. I will get back to you when it is ready.