Android Question Is it possible to save or serialize a StatusBarNotification object??

cheveguerra

Member
Licensed User
Longtime User
Hi everybody,

I am playing with the ReplyAuto library by @jsaplication.mobile (it is GREAT!!!!) and when I receive a notification, I am storing it in a customType:

The customType:
Class_Globals
Type lasNotis(number As String, notif As StatusBarNotification)

Sub ReplyAuto_NotificationPosted (SBN As StatusBarNotification)
    Dim noti As lasNotis
    noti.Initialize
    noti.number = SBN.Title
    noti.notif = SBN
    tempMap.Put(SBN.Title, noti)
End Sub

And later I can use the mapped notification object to send a message to that person:

To send message:
Sub sendMessage(theNumber)
    Dim t1 As lasNotis = tempMap.Get(theNumber)
    Dim t2 As StatusBarNotification = t1.notif
    notificationService.rp.reply(t2.Notification, "com.whatsapp", "Have a nice day!!")
End Sub

So this works alright, but I can only send messages to people that have sent me messages since the app started, when the app restarts for any reason, the customType also starts afresh ... so, I would like to save/store this customType, but whenever I try to serialize it, I get an error message saying that it cannot serialize object: StatusBarNotifications

The error:
Error occurred on line: 92 (B4XMainPage)
java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialize object: StatusBarNotification(pkg=com.whatsapp user=UserHandle{0} id=1 tag=E+ArBdTMGR8GrYh6E69jWa5DWEVOLuGFEdyKVrEduZA=
 key=0|com.whatsapp|1|E+ArBdTMGR8GrYh6E69jWa5DWEVOLuGFEdyKVrEduZA=
|10390: Notification(channel=individual_chat_defaults_80 [email protected] contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xffdb4437 groupKey=group_key_messages sortKey=1 actions=2 vis=PRIVATE publicVersion=Notification(channel=null shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0xffdb4437 category=msg vis=PRIVATE)))
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:285)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:224)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:224)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121)
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.WriteB4XObject(RandomAccessFile.java:326)
    at chv.replyauto.b4xmainpage._b_test_longclick(b4xmainpage.java:196)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$2.onLongClick(ViewWrapper.java:90)
    at android.view.View.performLongClickInternal(View.java:7535)
    at android.view.View.performLongClick(View.java:7493)
    at android.widget.TextView.performLongClick(TextView.java:12478)
    at android.view.View.performLongClick(View.java:7511)
    at android.view.View$CheckForLongPress.run(View.java:28270)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.RuntimeException: Cannot serialize object: StatusBarNotification(pkg=com.whatsapp user=UserHandle{0} id=1 tag=E+ArBdTMGR8GrYh6E69jWa5DWEVOLuGFEdyKVrEduZA=
 key=0|com.whatsapp|1|E+ArBdTMGR8GrYh6E69jWa5DWEVOLuGFEdyKVrEduZA=
|10390: Notification(channel=individual_chat_defaults_80 [email protected] contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xffdb4437 groupKey=group_key_messages sortKey=1 actions=2 vis=PRIVATE publicVersion=Notification(channel=null shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0xffdb4437 category=msg vis=PRIVATE)))
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:275)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:283)
    ... 28 more
** Activity (main) Pause event (activity is not paused). **
** Service (notificationservice) Destroy **
** Service (starter) Destroy (ignored)**
Notification internal service created
Packager_Notification_not_removedcom.digibites.accubattery
Packager_Notification_not_removedcom.digibites.accubattery

I have tried KVS, writeString, writeMap and WriteB4XObject, but always get the same error (Cannot serialize object: StatusBarNotification) ... SO .. is it possible to save a StatusBarNotification object? ?

Is there any other way to store it directly as an object without serialization or something?

Best regards
 

DonManfred

Expert
Licensed User
Longtime User
is it possible to save a StatusBarNotification object? ?
No. You can not store any Object. It is possible with a CustomType holding strings, single values (int, long, double, string) and bytearrays.
 
Upvote 0
Top