Android Question Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello all,

sometimes I'm getting the error when trying to post a notification:

Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package

Doing some research, I found many articles reporting the issue but without any solution. Does anybody had the same problem and know how to fix. I tried to catch the exception but without success... same error.

One of the realated articles: https://github.com/OneSignal/OneSignal-Android-SDK/issues/255
 

DonManfred

Expert
Licensed User
Longtime User
Should we guess how you build the notification?
You did not posted any line of code or even a full error
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Should we guess how you build the notification?
You did not posted any line of code or even a full error
Hello @DonManfred . I didn't post the code that builds the notification because after some research I found that could be an Android OS problem... and the same code runs sometimes 20x, 30x before getting the error.
But anyway, follows the code:

B4X:
Sub NotifyV6(UserImage As String,NotifyText As String)
    
    Dim Rp As RuntimePermissions
                                        
    Dim Folder As String = Rp.GetSafeDirDefaultExternal("shared")
    Dim FileName As String = "msgting.mpeg"
    Dim n As NB6
    n.Initialize("Mensagem Nexphone",Application.LabelName,"HIGH")
    n.SmallIcon(LoadBitmapResize(File.DirAssets,"logonexphone8.png",24dip,24dip,True))
    n.SetDefaults(False,True,True)
    n.AutoCancel(True)
    
                            
    If File.Exists(File.DirInternal,UserImage) Then
        n.LargeIcon(NativeMe.RunMethod("getRoundBitmap",Array(LoadBitmap(File.DirInternal,UserImage))))
    Else
        n.LargeIcon(NativeMe.RunMethod("getRoundBitmap",Array(LoadBitmap(File.DirAssets,"ic_person_black_48dp.png"))))
    End If
    
                                        
    Dim CsUri As String = CreateFileProviderUri(Folder, FileName)
    n.CustomSound(CreateFileProviderUri(Folder, FileName))
                                                                                
    Dim Notification As Notification
    Notification.Initialize
    Notification.OnGoingEvent = False
    Notification = n.Build("Nova Mensagem",NotifyText, "", chats)
    Try
        Notification.Notify(20)
        Sleep(200)
    Catch
        Log(LastException)
    End Try       
    
End Sub

I done some tries:

1. Catch the error with Try clause - no success

2. Sleep(200) after notify (sometimes many subsequent notification calls could make Android to refuse some update...) - no success

The event is quite aleatory - a standard that I could notice is that it occurs after some quantity of notifications in sequence (at least 5 or 6 notifications in a short time interval).

Any suggestion ?
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
1. Try to cancel the previous notification before you call Notify.
2. Test it with different notification ids.
Hello @Erel . Thanks for answering! Try to cancel the notification before raising a new in the same channel is a good idea. I noticed also that it's something related to the program "timing" and device performance because I fell that the bug occurs more in debug mode (at least in debug mode is consistent - I can reproduce the error when I want... with the program compiled and the device disconnected from computer it's less frequent ...)
I'm still testing the new behavior of Android 8 and notifications channels (can't change the notification characteristics of a channel - only uninstalling app) and the implications - but I have some data that says that the error maybe only occurs on Android 8+... I'll keep the community updated about the results.

Thanks again!
 
Upvote 0
Top