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 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!
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.
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.
When a new notification arrives, the OnNotificationReceived procedure will be invoked. Here the received message will be spoken
After that, in the afterSpeaking event of the Text To Speech component a short sound will be played by the Player component
The Notifier1.LogInfo blocks can help debugging using Logcat
Test
Tested on Samsung Galaxy A54 running Android 14.
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.
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?
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.
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.
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
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.
@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.
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.
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,