Firebase onTokenRefresh() is not called

后端 未结 13 2190
天命终不由人
天命终不由人 2020-11-27 16:59

In my MainActivityin my log, I can see the token using FirebaseInstanceId.getInstance().getToken() and it display the generated token. But it seem

13条回答
  •  佛祖请我去吃肉
    2020-11-27 17:27

    There are several reasons to not calling the onTokenRefresh methon not called. I have listed that and mention it one by one .

    1. Please make sure you have added the internet permission

    2. check have you added the google-services.json file that generate from google console inside of app directory in your project

    1. In your module Gradle file (usually the app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin:
    apply plugin: 'com.android.application'
    
    android {
      // ...
    }
    
    dependencies {
      // ...
      implementation 'com.google.firebase:firebase-core:16.0.4'
    
      // Getting a "Could not find" error? Make sure you have
      // added the Google maven respository to your root build.gradle
    }
    
    // ADD THIS AT THE BOTTOM
    apply plugin: 'com.google.gms.google-services'
    

    4) add the play service class path in project level build.gridle file

    buildscript {
        // ...
        dependencies {
            // ...
            classpath 'com.google.gms:google-services:4.1.0' // google-services plugin
        }
    }
    
    allprojects {
        // ...
        repositories {
            // ...
            google() // Google's Maven repository
        }
    }
    

    5) Make sure you have added those service in the AndroidManifes file inside application tag

    
        
            
        
    
    
    
        
            
        
     
    

    6) onToken refresh is called when token refresh and when install the app for the first so make sure you have deleted the app manually or clear the data

    7) Make sure you have extends the FirebaseMessagingService in your service class

    [Note : If its not working only for specific version for example android kitkat version then try to change the fcm version.]

提交回复
热议问题