Hello all,
i´m implmenting FCM into a project of a customer of mine.
Inside the Subscribetotopics i do a check if a token is available. If so then the token is send to my server and a php-script is saving the token and the device into a database.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
At the first run of the app the token seems to be empty...
My question: Can i use a timer or a small loop using sleep to check the existence of a token?
I mean:i want to call subscribetotopics multiple-times.
For now i use this and hopefully it is ok...
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Seems to work. Any comments in this?
			
			i´m implmenting FCM into a project of a customer of mine.
Inside the Subscribetotopics i do a check if a token is available. If so then the token is send to my server and a php-script is saving the token and the device into a database.
			
				B4X:
			
		
		
		Public Sub SubscribeToTopics
    fm.SubscribeToTopic(starter.Phone.GetSettings("android_id")) 'you can subscribe to more topics
    Log("Token: "&fm.Token)
    If fm.Token <> "" Then
        Dim j As HttpJob
        j.Initialize("",Me)
        j.Download2("http://urltophpscript",Array As String("action","register","token",fm.Token,"deviceID",starter.Phone.GetSettings("android_id")))
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Log(j.GetString)
        Else
            Log(j.ErrorMessage)
        End If
        j.Release
    End If
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
    '
End SubAt the first run of the app the token seems to be empty...
My question: Can i use a timer or a small loop using sleep to check the existence of a token?
I mean:i want to call subscribetotopics multiple-times.
For now i use this and hopefully it is ok...
			
				B4X:
			
		
		
		Public Sub SubscribeToTopics
    Log("SubscribeToTopics")
    fm.SubscribeToTopic(starter.Phone.GetSettings("android_id")) 'you can subscribe to more topics
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
    CheckToken
End Sub
Sub CheckToken
    Log("CheckToken: "&fm.Token)
    Do While fm.Token = ""
        'Log("Sleep250")
        Sleep(250)       
    Loop
    If fm.Token <> "" Then
        Log("Register Device with Token: "&fm.Token)
        Dim j As HttpJob
        j.Initialize("",Me)
        j.Download2("http://urltophpscript",Array As String("action","register","token",fm.Token,"deviceID",starter.Phone.GetSettings("android_id")))
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Log(j.GetString)
        Else
            Log(j.ErrorMessage)
        End If
        j.Release
    End If
End SubSeems to work. Any comments in this?
 
				 
 
		 
 
		