Android Question Permanent notifications sometimes appear

Alankoba

Member
Licensed User
Migrating from API 26 to 29 I noticed strange behavior in my app.
No reason a notification appears permanently (cannot be deleted)
I use Firebase notifications, but no messages have been sent to the app.


My FirebaseMessaging.b4a

B4X:
Sub Process_Globals
    Public fm As FirebaseMessaging
End Sub

Sub Service_Create
    fm.Initialize("fm")
End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("pedidoacaigoods_android_main")
    Log(fm.token)
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    CallSub3(Main, "msgPush", Message.GetData.Get("title"), Message.GetData.Get("body"))
End Sub

Sub called in fm_MessageArrived

B4X:
Sub msgPush(titulo As String, msg As String)
    Msgbox(msg, titulo)
End Sub

My Manifest

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
    
AddApplicationText(
 
<uses-library
      android:name="org.apache.http.legacy"
      android:required="false" />)
    

SetActivityAttribute (Main, android:exported, "true")
SetActivityAttribute (Main, android:taskAffinity, "")
SetActivityAttribute (Main, android:theme, "@android:style/Theme.DeviceDefault.Light")   

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
' fix api 29
SetApplicationAttribute(android:usesCleartextTraffic,"true")
'End of default text.

'Localizacao
AddPermission (android.permission.ACCESS_FINE_LOCATION)

CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)


B4A 9.01.2
FirebaseNotifications lib 1.21
 

Attachments

Alankoba

Member
Licensed User
On Samsung Galaxy smartphones (S8, S9, S10 With ONE UI) the problem still occurs even after the inclusion of the Service.StopAutomaticForeground line.

B4A Version 9.01.2

Is it a bug?
 

Alankoba

Member
Licensed User
B4X:
Sub Process_Globals
    Public fm As FirebaseMessaging
End Sub

Sub Service_Create
    fm.Initialize("fm")
End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("pedidoacaigoods_android_main")
    Log(fm.token)
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    Sleep(0)
    Service.StopAutomaticForeground 'remove if not using B4A v8+.  
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    CallSub3(Main, "msgPush", Message.GetData.Get("title"), Message.GetData.Get("body"))
End Sub

----


B4X:
Sub msgPush(titulo As String, msg As String)
    Msgbox(msg, titulo)
End Sub
 

Alankoba

Member
Licensed User
Yes, with the fix the problem stopped, but in the Samsung Galaxy continued to happen.

I removed the lines from the manifest and I will test again ...


Is it possible to test without waiting at random mode?
 

Alankoba

Member
Licensed User
The problem continues after removing the lines from the manifest. On Samsung Galaxy smartphones with Android 9.
B4A Updated (9.50 BETA 1)
 

Alankoba

Member
Licensed User
In Starter.bas I made the following change:

B4X:
Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub
It seems that the problem has been solved! But turning on the device, receiving a push notification and clicking it has no effect!

Clicking the notification only opens the app when the app has been manually opened at least once.
 
Top