I can not get registration ID from Android GCM

前端 未结 6 1297
小蘑菇
小蘑菇 2020-12-03 03:38

Although I try other answer about this problem, it can\'t be solved. Sender ID is correct, permissions are added, API key is true.

I use this post for creating the p

6条回答
  •  没有蜡笔的小新
    2020-12-03 04:02

    Do you have GCMIntentService defined correctly at the root package of your app?

    
    
      
        
        
        
      
    
    

    Make sure that "my_app_package" is identical to the main package of your app, or your id will return an empty string.

    Also notice that

        GCMRegistrar.register(this, "...");
    

    is asynchronous. Therefore, calling GCMRegistrar.getRegistrationId(this) immediately after that is not reliable, so you should avoid it.

    The id will arrive via broadcast callback to your GCMIntentService, as a part of the registration procedure. from there you can then store the gcm/fcm key anywhere you like, and use it in other parts of the application (usually on the server).

提交回复
热议问题