Java Question [Java Helper APP] Notification_Listener_Service Helper app

bitstra

Member
Licensed User
Longtime User
Because of I didn't managed it to get working b4a-library for Android 4.3 Notification_Listener_Service (NLS),
I've made a helper App complete in java:

NLSHelper.apk

This app can be installed hidden from App drawer, and it act as an Broadcast-Receiver/-Sender for using it from B4a projects.

After NLSHelper.apk is installed, it listens for Notifications from Android Notification_Listener_Service.
If an Broadcast for notification service is received this app sends a custom formatted broadcast, that can received by our b4a projects via manifest-xml-declared broadcast listener...

NLSHelper reacts on the following NLS-broadcasts by Android:

_onNotificationPosted
_onNotificationRemoved


It sends the following broadcasts to our b4a-projects:

for _onNotificationPosted:
B4X:
        Intent i2 = new  Intent("nlshelper.NLS_BR");
        i2.putExtra("notification_event", "onNotificationPosted /:/" + sbn.getPackageName() + "/:/"
                + sbn.getTag() + "/:/"
                + sbn.getNotification().tickerText + "/:/"
                + sbn.getId() + "/:/"
                + sbn.getNotification().contentIntent.getIntentSender() + "/:/"
                + "0x" + Integer.toHexString(sbn.getNotification().icon) + "/:/"
                + sbn.isOngoing() + "/:/"); //sbn.getNotification().toString());
        sendBroadcast(i2);


_onNotificationRemoved:
B4X:
        Intent i2 = new  Intent("nlshelper.NLS_BR");
        i2.putExtra("notification_event","onNotificationRemoved  /:/" + sbn.getPackageName() + "/:/" + sbn.getTag() + "/:/"
                + sbn.getNotification().tickerText + "/:/" + sbn.getId() + "/:/"
                + sbn.getNotification().toString());
        sendBroadcast(i2);


in our manifest.xml we have to declare the broadcast-listener for those broadcasts
in this example for my servicemodule 'srvnotificationlistener':
B4X:
        <receiver       
            android:name=".srvnotificationlistener$srvnotificationlistener_BR"
            android:enabled="true">
            <intent-filter>
                <action android:name="nlshelper.NLS_BR" />
            </intent-filter>
        </receiver>


After receiving the broadcast in b4a service module or activity we can split the Intents extras...

i.e.:
B4X:
Sub Service_Start (StartingIntent As Intent)
    'ToastMessageShow(StartingIntent.ExtrasToString,False)
   
    Dim intStr,pkg,tickertext,tag,id,notify,intentSender,IconResId,onGoing,parts() As String
   
   
    intStr=StartingIntent.ExtrasToString
   
    parts=Regex.Split("/:/",intStr)

    'Log(notify)
        pkg=parts(1)
        tag=parts(2)
        tickertext=parts(3)
        id=parts(4)
        notify=parts(5)   
        Try
          IconResId=parts(6)
          onGoing=parts(7)
        Catch
          IconResId=""
          onGoing=False
        End Try
              ...


and can react in our b4a project as follows:
B4X:
If parts(0).Contains("onNotificationPosted")=True Then
   'Do what ever you want here with extra's data
ElseIf parts(0).Contains("onNotificationRemoved")=TrueThen
   'Do what ever you want here with extra's data
End if

There are some more broadcast scenarios, that I can describe later or in sample project.
If anyone is interested in that solution, I could make a small sample project for the service...

The NLSHelper.APK ca be downloaded here: http://forum.xda-developers.com/showthread.php?t=2334221

This is my Bubble Launcher's XDA thread - Bubble Launcher uses the helper app for creating floating notifications in its user interface (there are screenshots in the xda-thread)...

BTW - Bubble Launcher itself is completely written B4A!
 

bluedude

Well-Known Member
Licensed User
Longtime User
Although I think it is great you created a solution practically this will not work because it needs to go through the Play store. It is already hard to get a user install one app. so let alone two apps. Not all users allow APK's from external sources.

Any reason why it cannot be done in a Library?
 

bitstra

Member
Licensed User
Longtime User
Although I think it is great you created a solution practically this will not work because it needs to go through the Play store. It is already hard to get a user install one app. so let alone two apps. Not all users allow APK's from external sources.

Any reason why it cannot be done in a Library?


I've build a Custom MessageBox with Link-Button to PlayStore and/or to an XDA download in my primary app, that guides my users to the preferred download (free on XDA / payed-donate on Play Store) After download and install the 'NLS Module APK' a broadcast-receiver in my primary app activates the downloaded NLSHelper.apk as module and guides the user to System Settings/Security/Notification Access to allow policy for it. The users are very satisfied with that procedure! And it runs very, very nice and stable in my 'Bubble Launcher' Ver. 2.1 from Play Store...

The reason for that were 2 aspects:

1. I simply didn't get it working in a b4a lib after many hours - To build the java app needed about one hour in Android studio and ran fine from scratch.

2. I wanted to have the option for a donate version module...

bitstra
 
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
So, all nice and clear but how could we use this?

Not going to redirect my users to a paid app. of somebody else :)

Also wondering if you talk about this operating as a "module" and not an app. How does that work with B4A?

Always prepared to pay for work other people do.
 

bitstra

Member
Licensed User
Longtime User
Hi bluedude,

my 'paid' app for NLSHelper in Play Store is declared as donate version. The same App without any restriction
can be downloaded free here: http://forum.xda-developers.com/attachment.php?attachmentid=2203337&d=1377072058
This is the link, that used by most users of my main app Bubble Launcher!
The ratio of downloads free:donate version is 100:5 atm...

This App can also be used by any b4a dev. and their users... :)

If you need the sample code to work with broadcasts by NLSHelper to an own app and vice versa, let me know it.
I can shorten a b4a service module as code snippet for your projects.

If that not option for you or your users, than you have to search for own solution :(
(Making a b4a lib is easy - making it work as stable as you want, is behalf that easy...)

-
Though I wouldn't understand that, because communicate with foreign apps via broadcasts
is one of the best things I've found within android operating system! - Examples are out of my skills: Camera apps, QR/barcode-scanners, Icon packs, chat-clients etc. All these are foreign for my users, and they accept that. Even one of my commercial industrial customers... (Don't invent a wheel a second time)


regards

bitstra
 
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

I would love to have some source code in B4A that uses the helper library. Pointing people to an .apk outside the Play Store is inconvenient because they need to have unknown resources enabled, and most of them don't get that part.

Pointing to your donation version is also not handy because I want to keep it totally free for them.

For a test its all fine and I would like to do that. Can you send me some sample code? Actually not sure how module apk's work.

Don't get me wrong, instead of donation I could pay for your work when I can use it inside my own project. Done that before with some other library developer(s).
 
Top