Notification Listener (powered by itoox-wrapper) and Itoo

This example uses the notification listener extension and itoo extension (Version 4).

What does the example app provide?
The example app listens to notifications and speaks its content while the app is in the background. This can be useful, if you want to listen to your received notifications while driving. Another use case could be to listen to incoming emails and play a sound after an order arrives (idea taken from here ).

Screenshot of the user interface

Screenshot of the blocks (Version 3)
The updated notification listener extension uses the new itoox-wrapper library by @Kumaraswamy, which helps to directly invoke Itoo (if present) to call procedures from the background. No persistent background service or persistent notification is required anymore!

While starting the service, you have to confirm notification access for the app.

The notification listener extension offers the 2 background procedures OnCreate and OnNotificationReceived, which will be called by Itoo from the background. These procedures run in the background, so it is not possible to use global variables or user interface components like labels, textboxes etc there.

How does it work?

  1. OnCreate will be initially called when Taifun notification listener begins. Here we register the events, in this case the AfterSpeaking event of the Text To Speech component.
  2. When a new notification arrives, the OnNotificationReceived procedure will be invoked. Here the received message will be spoken
  3. After that, in the afterSpeaking event of the Text To Speech component a short sound will be played by the Player component
  4. The Notifier1.LogInfo blocks can help debugging using Logcat

Test
Tested on Samsung Galaxy A54 running Android 14.

Source file Version 3
This example is 34

nlsitoo.aia (109.4 KB)

You will have to build the project to be able to use it.

Taifun
PS: Thank you very much @Kumaraswamy for helping me with the updates of the notificationlistener extension and providing your *itoox-wrapper* library! Thank you also for your powerful itoo extension! Without you this example would not have been possible.

10 Likes

Capture

In the highlighted area of the block, there is a text 'TextToSpeech1.AfterSpeaking'. Is it just a text (or name) or does it have any meaning? Can we write any text there?

And, below there is a text 'afterSpeaking'. Does it have any meaning? or Can we put any text there as our wish?

The text "TextToSpeech1.AfterSpeaking" refers to the event of TextToSpeech1:

image

and the second text "afterSpeaking" refers to the procedure that will be called just like the event, in background:

image

You may rename the second text if you also rename this procedure.

1 Like

Capture

In this block we can see the word ckbWhatsapp, is it another extension that is used in this tutorial project?

It is the checkbox component:

image

1 Like

May I know why 'after speaking' event is chosen (to register with itoo) instead of 'before speaking' or something similar to 'currently speaking'? Why future tense is preferred (To achieve what specific result)?

Update: I can guess the answer for this question as the project is aiming to play some music after the text notifications are converted to speech. But, when I use the app, I can hear only the voice of the text notifications and no music is played after that. So, still I'm in doubt.

Thankyou very much @Taifun for making this tutorial. This made me to complete my app.

you ony can register those events, which exist... the text to speech component offers the BeforeSpeaking and AfterSpeaking event, see also the documentation Media
As the example is designed, first the notification will be spoken and after that a short sound will be played, therefore the AfterSpeaking event was registered to play the sound.

it is a short sound of 1 second, actually the sound of a frog...
which device and Android version are you using for your tests?

For your purposes to play some music after a message arrived, you do not have to register the text to speech event... just play your music in the OnNotificationReceived procedure.

Taifun

1 Like

Thankyou

This app is not working when we close the app. But, working when we minimize it. The phone that I use is SM-A207F.

This is a Samsung A20? Which Android version?
Working fine for me on Samsung Galaxy A54 running Android 14
You might want to check Samsung | Don’t kill my app!
EDIT: disable batttery optimization, see also

Taifun

I noticed one thing. When we close the app and open it, we can see the quick shift of the message from ' Serivice is not running' to 'service is running'. So, it may mean that service is stop running while we close the app. But, I tested the older version of this app tutorial as well (that you posted before this one), it is working fine. Let me clarify again.

I screen recorded the video (You can see the quick shift of the message)

I tried the old version of this tutorial app once again. It can work even while we close the app. But, at beginning the app was not working, then I stopped the service and started again, after that it worked well.

The video for old version is in this link - WhatsApp Video 2024-01-23 at 20.49.29.mp4 - Google Drive

You lack some basic knowledge in App Inventor, I assume you do not know the Clock component in the demonstration.

I would recommend you to explore the resources posted above.

@Taifun , I am speaking about the app given in this tutorial post. I tried the old version that is posted one day before as well. That one is working (while the app is closed) in my phone but this one is not working in background. I shall upload that video as well.

Update: Yes, there may not be relationship between clock component & background processing. Okay, let me check.

@Kumaraswamy , yes, according to my life usecase, il learn the basics after taking my own time.

This is the video of the older version.

the example app checks in a Clock.Timer event, if the service is running
Unbenannt
and updates the text of label lblResult

Depending o the initial value of that label you see a quick flickering of that text


And as the initial text of version 2 is "service is NOT running", you see this quick flickering. Let me suggest you to change the initial value of that label to "Service is running" or just an empty text to see the difference.

If you have problems for the example app work in the background, then you should deactivate battery optimization as already mentioned earlier Notification Listener (powered by itoox-wrapper) and Itoo - #12 by Taifun

yes, first learning the basics would help you very much in being able to read and understand the blocks yourself

Taifun

1 Like

It works fine,
but if multiple notification received at same time, it doesn't read notification one by one, it skips to the latest,
tried with TinyDB but it works only when the app is open,

bg_notif_tinyDB.aia (103.7 KB)
Is it possible by any other methods?
@Taifun

Hi, can you please use the Store and Fetch property blocks offered by Itoo? Tiny DB does not always work properly in background.

But it too doesn't work in background, only works if the app is kept open