Alain75
Member
Hi,
I am developing an application which keeps a log of targeted notifications. The app lets the user choose from which packages the notifications are kept. I use of course the "NotificationListener" from @Erel which allows me to do the job.
Moreover, I am able to list all the fields of the notifications kept and to display them. It's nice, including the famous "key" which should allow my app to cancel the current notification without using its SBN, SBN I cannot serialize.
To cancel the notification (if it is still present), I use the internal method "cancelNotification" of the wrapper :
I call it with inline Java :
Unfortunately, I encountered the same error as @wes58 mentioned in his post, that is :
@wes58 mentionned a fix for the listener but I didn't find it in the forum. Am I mistaken ?
I am developing an application which keeps a log of targeted notifications. The app lets the user choose from which packages the notifications are kept. I use of course the "NotificationListener" from @Erel which allows me to do the job.
Moreover, I am able to list all the fields of the notifications kept and to display them. It's nice, including the famous "key" which should allow my app to cancel the current notification without using its SBN, SBN I cannot serialize.
To cancel the notification (if it is still present), I use the internal method "cancelNotification" of the wrapper :
Part of NotificationListenerWrapper:
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
if (intent.hasExtra("b4a_cancel_all")) {
this.cancelAllNotifications();
} else if (intent.hasExtra("b4a_cancel")) {
StatusBarNotification sbn = getSbnFromIntent(intent);
if (VERSION.SDK_INT >= 21) {
try {
String key = (String)sbn.getClass().getMethod("getKey").invoke(sbn);
this.getClass().getMethod("cancelNotification", String.class).invoke(this, key);
} catch (Exception var11) {
throw new RuntimeException(var11);
}
} else {
this.cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());
}
} else if (intent.hasExtra("b4a_getactive")) {
StatusBarNotification[] all = this.getActiveNotifications();
if (all != null) {
StatusBarNotification[] var8 = all;
int var7 = all.length;
for(int var6 = 0; var6 < var7; ++var6) {
StatusBarNotification sbn = var8[var6];
try {
this.startService(this.createIntent("posted", sbn));
} catch (ClassNotFoundException var10) {
throw new RuntimeException(var10);
}
}
}
}
I call it with inline Java :
Part of my NotificationService:
Sub DismissNotification(key As String)
Dim jo As JavaObject = Me
Try
Log("Dismiss "&key)
jo.RunMethodJO("cancelKey",Array(key))
Catch
Log(LastException)
End Try
End Sub
#If JAVA
public void cancelKey(String key) {
try {
this.getClass().getMethod("cancelNotification", String.class).invoke(this, key);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
#End If
Unfortunately, I encountered the same error as @wes58 mentioned in his post, that is :
Error received:
Dismiss 0|b4a.test1|233|null|10376
(IllegalArgumentException) java.lang.IllegalArgumentException: Expected receiver of type b4a.journal.notificationservice, but got java.lang.Class<b4a.journal.notificationservice>
@wes58 mentionned a fix for the listener but I didn't find it in the forum. Am I mistaken ?