hi,
my app crash on some devices with this error as
com.studentapp.librasoft.firebasemessaging.handleStart
java.lang.RuntimeException
its reported by google playstore, i use firebasemessaging in my APP
my app crash on some devices with this error as
com.studentapp.librasoft.firebasemessaging.handleStart
java.lang.RuntimeException
its reported by google playstore, i use firebasemessaging in my APP
firebasemessging module:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Private fm As FirebaseMessaging
End Sub
Sub Service_Create
Try
If fm.IsInitialized = False Then
fm.Initialize("fm")
End If
CreateChannelIfNeeded
Log("FirebaseMessaging initialized")
Catch
Log("Service_Create Error")
Log(LastException.Message)
Log(LastException)
End Try
End Sub
Public Sub SubscribeToTopics
Try
If fm.IsInitialized = False Then
fm.Initialize("fm")
End If
If B4XPages.MainPage.CELL_num <> "" Then
fm.SubscribeToTopic(B4XPages.MainPage.CELL_num)
Log("Subscribed to topic : " & B4XPages.MainPage.CELL_num)
End If
Catch
Log("SubscribeToTopics Error")
Log(LastException.Message)
Log(LastException)
End Try
End Sub
Sub Service_Start (StartingIntent As Intent)
Try
If fm.IsInitialized = False Then
fm.Initialize("fm")
CreateChannelIfNeeded
End If
If StartingIntent <> Null Then
If StartingIntent.IsInitialized Then
Log("HandleIntent Start")
fm.HandleIntent(StartingIntent)
Log("HandleIntent End")
End If
End If
Catch
Log("Service_Start Error")
Log(LastException.Message)
Log(LastException)
End Try
Service.StopAutomaticForeground
End Sub
Sub fm_MessageArrived (Message As RemoteMessage)
Try
Log("Message Arrived")
Dim title As String = "Notification"
Dim body As String = ""
If Message <> Null Then
If Message.GetData.IsInitialized Then
If Message.GetData.ContainsKey("title") Then
title = Message.GetData.Get("title")
End If
If Message.GetData.ContainsKey("body") Then
body = Message.GetData.Get("body")
End If
End If
End If
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim pkg As String = ctxt.RunMethod("getPackageName", Null)
Dim res As JavaObject
res = ctxt.RunMethod("getResources", Null)
Dim iconId As Int
iconId = res.RunMethod("getIdentifier", Array("icon", "drawable", pkg))
If iconId <= 0 Then
iconId = Application.Icon
End If
Dim builder As JavaObject
builder.InitializeNewInstance( _
"androidx.core.app.NotificationCompat$Builder", _
Array(ctxt, "default_channel_id"))
builder.RunMethod("setSmallIcon", Array(iconId))
builder.RunMethod("setContentTitle", Array(title))
builder.RunMethod("setContentText", Array(body))
builder.RunMethod("setAutoCancel", Array(True))
builder.RunMethod("setPriority", Array(1))
Dim bigTextStyle As JavaObject
bigTextStyle.InitializeNewInstance( _
"androidx.core.app.NotificationCompat$BigTextStyle", Null)
bigTextStyle.RunMethod("bigText", Array(body))
builder.RunMethod("setStyle", Array(bigTextStyle))
Dim intent As Intent
intent.Initialize(intent.ACTION_MAIN, "")
intent.SetComponent(Application.PackageName & "/.Main")
intent.Flags = Bit.Or(0x10000000, 0x20000000)
Dim piClass As JavaObject
piClass.InitializeStatic("android.app.PendingIntent")
Dim FLAG_IMMUTABLE As Int
Try
FLAG_IMMUTABLE = piClass.GetField("FLAG_IMMUTABLE")
Catch
FLAG_IMMUTABLE = 0x04000000
End Try
Dim pendingFlags As Int = FLAG_IMMUTABLE
Dim pi As JavaObject
pi.InitializeStatic("android.app.PendingIntent")
Dim PendingIntentObject As Object = pi.RunMethod("getActivity", _
Array(ctxt, 0, intent, pendingFlags))
builder.RunMethod("setContentIntent", Array(PendingIntentObject))
Dim manager As JavaObject
manager = ctxt.RunMethod("getSystemService", Array("notification"))
Dim NotificationID As Int
NotificationID = DateTime.Now Mod 2147483647
manager.RunMethod("notify", _
Array(NotificationID, builder.RunMethod("build", Null)))
Log("Notification displayed")
Catch
Log("fm_MessageArrived Error")
Log(LastException.Message)
Log(LastException)
End Try
End Sub
Sub CreateChannelIfNeeded
Try
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim ver As JavaObject
ver.InitializeStatic("android.os.Build$VERSION")
Dim sdk As Int = ver.GetField("SDK_INT")
If sdk >= 26 Then
Dim nm As JavaObject
nm = ctxt.RunMethod("getSystemService", Array("notification"))
Dim channel As JavaObject
channel.InitializeNewInstance( _
"android.app.NotificationChannel", _
Array("default_channel_id", "Default", 4))
nm.RunMethod("createNotificationChannel", Array(channel))
End If
Catch
Log("CreateChannelIfNeeded Error")
Log(LastException.Message)
Log(LastException)
End Try
End Sub
Sub Service_Destroy
Log("Firebase Service Destroyed")
End Sub