Android Question Intent to hide notifications

marcick

Well-Known Member
Licensed User
Longtime User
I have a background service with its related persistent notification in the status bar.
I know it is possible to manually hide this notification in settings-notification, but I want to show a msgbox to ask the user if he wants to hide this notification.
I see Cerberus App does this, I suppose an intent is needed.
Any help ?
Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that there is no reason to have more than one persistent notification. A single foreground service will cause the whole process to be in the foreground state.

I guess that you are talking about these settings:
https://stackoverflow.com/questions...-the-android-notification-settings-for-my-app

I'm not sure what will happen if you try to start a foreground service while the user disabled notifications for your app. you will need to test it.

It should be simple to create an intent based on that answer.
You can get the uid with:
B4X:
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim uid As Int = ctxt.RunMethodJO("getApplicationInfo", Null).GetField("uid")
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Thank you. You guess correct.
I'll test that intent tomorrow, I'm sure it works.
I see better that Cerberus app, does not call the intent, but just show a msgbox and ask the user if he wants to hide the notification, then automatically apply this settings.
During installation I see Cerberus asks the permission to modify system settings.
So the new question is, how to automatically set the app to hide the notification (and which permission is required).
I did some tests yesterday and looks like the service runs forever also when notifications are disabled (otherwise Cerberus would not works ....).
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Some more details on how Cerberus works:

First you have to accept this
Resizer_15737561200160.jpg


Then the first notification is this

Resizer_15737561200161.jpg


If you long press the notification then you see

Resizer_15737561200162.jpg


If you choose Minimize you will no longer see the notification and the app works forever in background.
I would like to do the same.
 
Upvote 0
Top