Android Question can‘t get hms token

hamll

Member
B4X:
Wait For (hms.GetPushToken("1049***563")) complete(Token As String)

    Log( Token)

i can‘t get hms token
 

hamll

Member
when i use huawei HMS, it worked. but i want to get the device token, it dose not work
B4X:
Sub Class_Globals
Private hms As HMSManager
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    hms.Initialize
    hms.EnableLogs
    Root = Root1
    Root.LoadLayout("MainPage")
    Wait For (hms.GetPushToken("104***63")) complete(Token As String)
    Log( "Token:"& Token)
End Sub

log:
B4X:
Token:
onNewToken: 08661470320657183*********01
Token is null

how can i use onNewToken? thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Now the question is clear. Note that the token is not too important in most cases. It is simpler to send messages to topics.

Try this:
B4X:
Wait For (GetToken) Complete (Token As String)


Public Sub GetToken As ResumableSub
  For i = 1 To 5
   Wait For (hms.GetPushToken("104***63")) complete(Token As String)
   If Token <> "" Then Return Token
   Sleep(500)
 Next
 Return ""
End Sub
 
Upvote 0

hamll

Member
B4X:
Wait For (GetToken) Complete (Token As String)


Public Sub GetToken As ResumableSub
  For i = 1 To 5
   Wait For (hms.GetPushToken("104***63")) complete(Token As String)
   If Token <> "" Then Return Token
   Sleep(500)
 Next
 Return ""
End Sub
it dose not work

i got 5 onNewToken, but token still null


how can i use onNewToken ,it is in log , from hms.EnableLogs
 
Upvote 0

hamll

Member
maybe" hms.GetPushToken" Return null

B4X:
baseCallBack.onComplete
receive msg status_code:0, error_code0, api_name:push.gettoken, app_id:10******3|, pkg_name:myt.test, session_id:*,

GetTokenTask receive a empty token, please check HmsMessageService.onNewToken receive result.

push receive broadcast message, Intent:com.huawei.android.push.intent.REGISTRATION pkgName:myt.test
receive a push token: myt.test
remote service bind service start


*** Service (hmsmessagingservice) Create ***
start to bind
remote service onConnected
remote service unbindservice
handle message start 
onNewToken


onNewToken: 08661470***********************1
start to destroy
 
Upvote 0

hamll

Member
I think tihs is a bug
when i use
B4X:
 Wait For (hms.GetAAID) complete(AAID As String)

it worked. but the sub GetPushToken can't get token.

HMS server need token to send push message
 
Upvote 0
Top