产生的FCM令牌为无效,可能与所使用的依赖关系发生冲突



最初,当我为Android应用程序创建项目时,FCM已集成了成功,我能够接收FCM令牌。但是,当我在项目中添加更多功能和依赖性时,我将FCM代币视为null。以下是我对所使用的依赖项的看法

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile('org.apache.httpcomponents:httpcore:4.4.1') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }    
    compile('com.google.api-client:google-api-client-android:1.22.0')
    compile('com.google.apis:google-api-services-script:v1-rev6-1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    compile 'pub.devrel:easypermissions:0.1.5'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.github.markushi:circlebutton:1.1'
    compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
    compile 'cn.pedant.sweetalert:library:1.3'
    compile 'me.spark:submitbutton:1.0.1'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.google.firebase:firebase-messaging:9.8.0'
    compile 'com.google.android.gms:play-services-auth:9.8.0'
    compile 'com.google.android.gms:play-services-appindexing:9.8.0'
    testCompile 'junit:junit:4.12'
    compile files('libs/org.apache.http.legacy.jar')
}

这是我的MyFireBaseInstanceIdService

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
    private static final String TAG = "MyFirebaseIIDService";
    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. Note that this is called when the InstanceID token
     * is initially generated so this is where you would retrieve the token.
     */
    // [START refresh_token]
    @Override
    public void onTokenRefresh() {
        Log.d(TAG,"Entered MyFirebaseInstanceIDService");
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);
        sendRegistrationToServer(refreshedToken);
    }
    // [END refresh_token]
    private void sendRegistrationToServer(String token) {
        // TODO: Implement this method to send token to your app server.
    }
}

这就是我记录FCM令牌的方式:

 String refreshedToken = FirebaseInstanceId.getInstance().getToken();
            Log.d(TAG, "Refreshed token: " + refreshedToken);

我认为这与FCM与Google-API-CLIENT依赖性有所冲突。有人可以指出,到底出了什么问题?

在我的应用程序标签中,在subest.xml中,刚刚删除工具:node =" replace" ,然后开始工作。

FirebaseInstanceIdService中的OntokenRefresh仅在生成新的令牌时才调用。如果您的应用程序以前是安装并生成的令牌,则不会调用OntokenRefresh。尝试卸载并重新安装应用程序以强迫新的代币产生,这将导致ordokenrefresh被称为。

希望它可以解决您的问题。请参阅此链接以进行FCM.FireBase Cloud Messaging

最新更新