Android Question FCM Token Generation Problem

MrSm1Th

Member
Hi, I've a problem with FCM.
I think Everything is ok and I checked many times but token not generated.
I tried many times to solve the problem and search in forum and Google but I couldn't find anything. ( i found just loops after fm.Initialize or sleep(n) method , But not working )
also i checked Server API and "google-services.json" file .

B4A : Version 10
Libraries : FirebaseNotification / Firebase Analytics / ....
part of codes =>>

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

FirebaseMessaging [Service]:
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

Sub Process_Globals
    Private fm As FirebaseMessaging
End Sub

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

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("general")
    Log(fm.IsInitialized)  'Result = true
    Log(fm.Token)           'Result = Nothing
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    Sleep(0)
    Service.StopAutomaticForeground
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    n.Notify(1)
End Sub

Sub Service_Destroy

End Sub

Starter [ Service ]:
Sub Process_Globals
    Public Provider As FileProvider
End Sub

Sub Service_Create
    CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
    Provider.Initialize
End Sub



Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub

/ Tnx /
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

MrSm1Th

Member
1. Step is to Update to B4A 10.7
2. Step is to install a new SDK

I install the last B4a Version and my SDK is Ok
but nothing changed

** yesterday I tested my codes and all were ok. i saved some tokens and sent notifications to my clients .
** I added one more manifest permission for hiding my app in " recent apps" , I think it causes the problem. but I deleted that and the problem still there
 
Last edited:
Upvote 0

MrSm1Th

Member
The token might not be available immediately.

You can do something like:
B4X:
Do While fm.Token = ""
    Sleep(100)
Loop
Log(fm.Token)

I did it but didn't work. I said in the first post.
I upload a simple project. this simple project didn't work on my virtual device and didn't work on my personal smartphone.
please put "google-services.json" in root directory of this project. because of my server API key, I deleted that.

Edited :
** I upgraded google play services on my phone but nothing changed
** also I deleted my project in google firebase and created a new project and downloaded a new google-services.json , but nothing changed
 

Attachments

  • NotifTest.zip
    73 KB · Views: 192
Last edited:
Upvote 0
Top