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

See here:

1 Like

... and here:

1 Like

You are always very kind and thorough in explanations.
I have one last question, (I hope):
It is possible to restore the app icon, upon receipt of the number I send, with the mobile phone in suspension.

Hi everyone
I made an application using the servicio extension that receives a coordinate through the location sensor every second and sends it to Google Sheet. This application works well for a few minutes at first, but after a few minutes it stops. My phone model is Huawei y6 prime 2019 with Android 9. Please if anyone can help me. I will send the designed blocks.

Try if this example works for you:

2.- Example app.

Servicio.aia (104.9 KB)

1 Like

Thanks for your prompt reply
But unfortunately, there is still the same problem as before.
I checked your extension, but the minimize screen to background block is missing. Maybe if we use this block as foreground, the problem will be solved.

Hello
Is it possible to send me the Servicio extension that includes the minimize screen to background block?
Because I downloaded this extension, but it doesn't have this block, and in the example you provided, I noticed that this block is there.

http://kio4.com/appinventor/147_extension_servicio_rush.htm

Extension com.kio4.servicio.aix contains Background block

can you send me aia file of this apk?

Which APK?
Btw, I don't keep every app (aia) I made for testing purposes. Otherwise there would be thousands.

Hello
I want the aia file of this apk which you uploaded in this link "ServicioCuenta_2.apk - Google Drive". When I check the aia file in this link "https://community.appinventor.mit.edu/uploads/short-url/dcaBWSnrOnXR6OBIwlnIkcy6BgU.aia", my phone closes after a few minutes. But when I use your apk file, it works properly. If you don't have the file, if possible, please guide me to create it.

I used a Foreground service to prevent Doze mode on Android 6+ (API ≥ 23).
I've pointed this out many times in the last years (also in the old AI2 forum).
Search the forum (for "radio", "radio app", "streaming app" etc ...).

For app apps that use location services it seems to get more complicated and they must request location permissions (btw, I've never used it myself):

@Juan_Antonio Servicio used to work with Android 11; recently updated to Android 12 and the extension is broken.

This extension unfortunately does not work anymore after the SDK31 release...
Get an error message indicating that the app must specify FLAG_IMMUTABLE when creating a PendingIntent...

Hopefully you can update it? It has been a very useful extension. :slight_smile:

Thanks,
Steve

Thanks @SteveJG for testing it.

It seems the problem is...
https://stackoverflow.com/questions/70889493/android-12-pending-intent

I have changed these lines in the source code...

///////////////////////////////////////////// NOTIFY /////////////////////////////
@SimpleFunction(description  = "Notify in status bar.")
public void Notify(String title, String text){
final Intent intentNotification = new Intent("action_call_method");
// PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentNotification, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
	   pendingIntent = PendingIntent.getBroadcast(context, 0, intentNotification, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
    }else {
        pendingIntent = PendingIntent.getBroadcast(context, 0, intentNotification, PendingIntent.FLAG_UPDATE_CURRENT);
    }

I have updated the extension, but have not tested it.
Can someone try it? Thanks.

Servicio_v2.aia (106.5 KB)

com.kio4.servicio.aix (102.2 KB)

Works fine in one app. Will try another in a while though expect it too will be ok on Android 12.

Thank you very much

1 Like

Tried version 2 of the extension on my player app (using app inventor player component).
After launching the app and selecting my folder of flac songs to play, I then set the app to background (servicio.ToBackground)

It played for 12 hours without getting killed by the system!

I had also used UrsAI2Wakelock to set a wakelock. Don't know if that was like overkill.

Maybe the combination of the two extensions helped to not kill my app.

The player app was running on Android 6 on LG X Power.

This permission is declared in the Manifest:
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>

If you intend to publish the app on the Play Store:

See e.g. here.

Thanks. My player is for personal use only.

I have tested in my Samsung s21U android 13 and it work. I modified a couple of lines in service.java and added a permission in the manifest file so that it works correctly on Android 13.

    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
@SimpleFunction(description  = "Notify in status bar.")

public void Notify(String title, String text){

    final Intent intentNotification = new Intent("action_call_method");

    int pendingFlags;

    if (Build.VERSION.SDK_INT >= 23) {

    pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;

    } else {

    pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT;

    }

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentNotification, pendingFlags);
  
...

[mod edit direct link to another developer's extension removed. Or did @Juan_Antonio provide you with the source code so that you could modify his extension ? Or did you decompile and hack his extension, then recompile and upload here ?]