Android Question What are Android Rules-2025 for non-stop app ?

peacemaker

Expert
Licensed User
Longtime User
Hi, All

Who recently was creating an app like a messenger, that must be "forever online" (without Google Play Market publish) ?
Please, help to collect the latest actual rules list: what the app must contain to work all-the-time even after screen off button.

1. Notification permission
2. Notification icon
3. Foreground service type
AddPermission(android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK)
SetServiceAttribute(serv, android:foregroundServiceType, "mediaPlayback") 'choose the type
4. Foreground service
5. PhoneWakeState ? How better for a messenger ?

Correct ? What more ?
p.s. the applied task is a WiFi local intranet messenger. It does not work with all these steps when the device screen is switched off by the button.
 

peacemaker

Expert
Licensed User
Longtime User
use push notifications like all other apps.
But how to be with LAN intranet P2P serverless messenger that does not even need Internet ?
 
Last edited:
Upvote 0

Sandman

Expert
Licensed User
Longtime User
It will not work reliably, at least not on all devices.
I can't stress this enough. You might very well think you've solved it for your app, because it seems to work just as you want it. But sooner or later you will start getting user comments about it not working on their phones. When you investigate, you'll find that they use different brands, that obviously have tweaked the settings for the OS. And you won't be able to solve it.

You will lose this fight.

use push notifications like all other apps
This is the way.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
So, even for LAN intranet app - a local server is required for Firebase notif?
Now just broadband UDP is used, without server. But when the power button switched the phone off - after 5 secs app is stopped to work, with foreground service.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
A simple B4J app (it can be a http server)
But anyway non-stop working server host :)

Ah, some important update: this LAN intranet messaging app is ... a voice intercom app. So, it needs to listen to a microphone all the time, to be activated.
So, the task is indeed "forever online" app.
And one smartphone is already a public place "server".

But are you sure that it's impossible for Android app development now in 2025 ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
But are you sure that it's impossible for Android app development now in 2025 ?
It was actually possible in older versions of Android. Theoretically it should work with a foreground service. Practically it works on some devices. Test the background location example.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I tried to make the same as background location example, and can confirm that the app with foreground service (UDP intranet networking) at phones (Samsung A23 (Android 14) and Xiaomi Redmi Note 10 Pro (Android 13)), at both the app is set up not to be blocked by the OS in power:

1. The network data is transceived OK all the time (via B4A-bridge logs), including after the switched off screen. But only from Samsung.
2. Xiaomi in 4-5 mins - stopped the data transmission, resumes only if to switch the screen on, but after off again - stop in some seconds.
3. Voice messages are playable only if the screen is on. Despite the wakelocks.
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
And final good news: if to add Firebase pushes in addition to intranet UDP voice messaging with the foreground service:
  1. Wakelocks are not needed, in whole, push wakes the phone
  2. This my wakelock research helps to make voice messaging automatically OK ! (when screen is on from the push-message)
  3. Messaging is still serverless (if Firebase ignored :)).
  4. Both phones work OK, i mean, any can.
p.s. and app has turned out ... not only intranet :cool: (when data is sent not only via UDP, but in push-message also)
 
Upvote 0
Top