<legend id='07Clg'><style id='07Clg'><dir id='07Clg'><q id='07Clg'></q></dir></style></legend>

  1. <small id='07Clg'></small><noframes id='07Clg'>

    <tfoot id='07Clg'></tfoot>

      <i id='07Clg'><tr id='07Clg'><dt id='07Clg'><q id='07Clg'><span id='07Clg'><b id='07Clg'><form id='07Clg'><ins id='07Clg'></ins><ul id='07Clg'></ul><sub id='07Clg'></sub></form><legend id='07Clg'></legend><bdo id='07Clg'><pre id='07Clg'><center id='07Clg'></center></pre></bdo></b><th id='07Clg'></th></span></q></dt></tr></i><div id='07Clg'><tfoot id='07Clg'></tfoot><dl id='07Clg'><fieldset id='07Clg'></fieldset></dl></div>

        <bdo id='07Clg'></bdo><ul id='07Clg'></ul>

      FirebaseInstanceIdService getToken 返回 null

      时间:2023-07-30
    1. <tfoot id='SP1I6'></tfoot>
      <i id='SP1I6'><tr id='SP1I6'><dt id='SP1I6'><q id='SP1I6'><span id='SP1I6'><b id='SP1I6'><form id='SP1I6'><ins id='SP1I6'></ins><ul id='SP1I6'></ul><sub id='SP1I6'></sub></form><legend id='SP1I6'></legend><bdo id='SP1I6'><pre id='SP1I6'><center id='SP1I6'></center></pre></bdo></b><th id='SP1I6'></th></span></q></dt></tr></i><div id='SP1I6'><tfoot id='SP1I6'></tfoot><dl id='SP1I6'><fieldset id='SP1I6'></fieldset></dl></div>
        <legend id='SP1I6'><style id='SP1I6'><dir id='SP1I6'><q id='SP1I6'></q></dir></style></legend>

            <small id='SP1I6'></small><noframes id='SP1I6'>

                <bdo id='SP1I6'></bdo><ul id='SP1I6'></ul>

                  <tbody id='SP1I6'></tbody>
                本文介绍了FirebaseInstanceIdService getToken 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试将 FCM 通知添加到我的应用中,但出于某种原因

                Im trying to add FCM notifications to my app, but for some reason

                FirebaseInstanceId.getInstance().getToken();
                

                正在返回 null.

                由于我没有得到任何堆栈跟踪,我最好的猜测是 FirebaseInstanceIdService 不工作

                Since im not getting any stacktrace my best guess is that FirebaseInstanceIdService is not working

                • Google Play 服务版本:9.6.1
                • Firebase 消息传递版本:9.6.1
                • 从 FirebaseConsole 添加了 json 配置文件(尝试了单个文件,其中包含 2 个客户端,一个用于调试,一个用于发布构建)和 2 个文件,每个用于各自的构建

                我在我的模块 gradle 脚本的底部应用了谷歌服务插件在项目根 gradle 脚本中包含谷歌服务

                Iw applied google services plugin at the bottom of my modules gradle script Included google services in projects root gradle script

                根据官方文档创建了 2 个服务:

                Created 2 services from the officail docs:

                public class MyFirebaseInsanceIDService  extends FirebaseInstanceIdService {
                
                private static final String TAG = "MyFirebaseIIDService";
                
                @Override
                public void onTokenRefresh() {
                    // Get updated InstanceID token.
                    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
                    PreferencesHelper.putSharedPreferencesString(Constants.User.PUSH_NOTIFICATIONS, refreshedToken);
                
                    Log.e("TOKEN", "Token: " + FirebaseInstanceId.getInstance().getToken());
                }
                

                }

                还有清单:

                <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                package="com.fc.test">
                
                <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
                <uses-permission android:name="android.permission.INTERNET" />
                
                <application
                    android:name="fctest"
                    android:allowBackup="true"
                    android:icon="@mipmap/ic_launcher"
                    android:label="${appName}${appNameSuffix}"
                    android:supportsRtl="true"
                    android:theme="@style/AppTheme"
                    tools:node="replace">
                
                    <service
                        android:name="com.fc.test.MyFirebaseInsanceIDService"
                        android:enabled="true"
                        android:exported="true">
                        <intent-filter>
                            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
                        </intent-filter>
                    </service>
                
                    <service
                        android:name="com.fc.test.MyFirebaseMessagingService"
                        android:enabled="true"
                        android:exported="true">
                        <intent-filter>
                            <action android:name="com.google.firebase.MESSAGING_EVENT" />
                        </intent-filter>
                    </service>
                
                    <activity
                        android:name="com.fc.test.view.splash.Splash"
                        android:screenOrientation="portrait"
                        android:theme="@style/AppTheme.CenterAnimation">
                        <intent-filter>
                            <action android:name="android.intent.action.MAIN" />
                
                            <category android:name="android.intent.category.LAUNCHER" />
                        </intent-filter>
                    </activity>
                
                </application>
                

                根 Gradle:

                buildscript {
                    repositories {
                        jcenter()
                        maven { url 'https://maven.fabric.io/public' }
                    }
                    dependencies {
                        classpath 'com.android.tools.build:gradle:2.1.2'
                        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
                        //noinspection GradleDynamicVersion
                        classpath 'io.fabric.tools:gradle:1.+'
                        classpath 'com.google.gms:google-services:3.0.0'
                    }
                }
                
                allprojects {
                    repositories {
                        jcenter()
                        maven { url "http://dl.bintray.com/drummer-aidan/maven" }
                        maven { url "https://maven.fabric.io/public" }
                        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
                        maven { url "https://jitpack.io" }
                    }
                }
                
                ext {
                    buildToolsVersion = '24.0.1'
                    compileSdkVersion = 24
                    minSdkVersion = 15
                    targetSdkVersion = 24
                    supportLibraryVersion = '24.2.1'
                }
                

                以及Gradle模块的主要部分

                and the main part of the modules Gradle

                    dependencies {
                    final PLAY_SERVICES_VERSION = '9.6.1'
                    final SUPPORT_LIBRARY_VERSION = '24.2.1'
                    final RETROFIT_VERSION = '2.1.0'
                    final DAGGER_VERSION = '2.5'
                    final DEXMAKER_VERSION = '1.4'
                    final HAMCREST_VERSION = '1.3'
                    final ESPRESSO_VERSION = '2.2.1'
                    final RUNNER_VERSION = '0.4'
                    final BUTTERKNIFE_VERSION = '8.1.0'
                    def daggerCompiler = "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
                    def jUnit = "junit:junit:4.12"
                    def mockito = "org.mockito:mockito-core:1.10.19"
                    // App Dependencies
                    compile "com.google.android.gms:play-services-gcm:$PLAY_SERVICES_VERSION"
                    compile "com.google.firebase:firebase-messaging:$PLAY_SERVICES_VERSION"
                    compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
                    compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
                    compile "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
                    compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION"
                    compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
                    compile "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
                    compile "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
                    compile "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
                    compile "com.squareup.retrofit2:adapter-rxjava:$RETROFIT_VERSION"
                    compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
                    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
                        transitive = true;
                    }
                }
                apply plugin: 'com.google.gms.google-services
                

                • 请注意,我在我的根应用程序标记中使用 tools:node="replace".FirebaseInstanceIdService 是否有可能没有添加到清单中,因为它与我的 FirebaseInstanceService 具有相同的意图过滤器,因此没有被调用?
                  • Note that im using tools:node="replace" in my root application tag. Is it possible that FirebaseInstanceIdService is not added to the manifest since it has the same intent filter as mine FirebaseInstanceService and thus not being called?
                  • 所以我的问题是官方文档或我的实现中是否有问题导致实例令牌为空?

                    So my question here would be is there something wrong it the official docs or in my implementation that should cause the Instance token to be null?

                    推荐答案

                    在挖掘了 FCM 的旧实现和生成的清单之后,我现在可以说清单合并是问题所在.

                    After digging up thru old implementations of FCM and generated manifests, I can now say that manifest merger is the problem.

                    此问题的解决方案是将这些类手动添加到应用清单中

                    Solution for this problem is adding these classes to the apps manifest manualy

                     <activity
                            android:name="com.google.android.gms.common.api.GoogleApiActivity"
                            android:exported="false"
                            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
                    
                        <meta-data
                            android:name="com.google.android.gms.version"
                            android:value="@integer/google_play_services_version" />
                    
                        <service
                            android:name="com.google.firebase.messaging.FirebaseMessagingService"
                            android:exported="true" >
                            <intent-filter android:priority="-500" >
                                <action android:name="com.google.firebase.MESSAGING_EVENT" />
                            </intent-filter>
                        </service>
                    
                        <receiver
                            android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
                            android:exported="true"
                            android:permission="com.google.android.c2dm.permission.SEND" >
                            <intent-filter>
                                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                    
                                <category android:name="com.fc.debug" />
                            </intent-filter>
                        </receiver>
                    
                    
                        <receiver
                            android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
                            android:exported="false" />
                        <!--
                    
                        -->
                        <service
                            android:name="com.google.firebase.iid.FirebaseInstanceIdService"
                            android:exported="true" >
                            <intent-filter android:priority="-500" >
                                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
                            </intent-filter>
                        </service>
                    
                        <provider
                            android:name="com.google.firebase.provider.FirebaseInitProvider"
                            android:authorities="com.fc.debug.firebaseinitprovider"
                            android:exported="false"
                            android:initOrder="100" />
                    
                        <receiver
                            android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
                            android:enabled="true" >
                            <intent-filter>
                                <action android:name="com.google.android.gms.measurement.UPLOAD" />
                            </intent-filter>
                        </receiver>
                    
                        <service
                            android:name="com.google.android.gms.measurement.AppMeasurementService"
                            android:enabled="true"
                            android:exported="false" />
                    

                    这篇关于FirebaseInstanceIdService getToken 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:计算 Firebase 云消息传递中某个主题的订阅者 下一篇:Firebase 云消息传递不同的密钥

                相关文章

                • <bdo id='dVNrC'></bdo><ul id='dVNrC'></ul>

                <small id='dVNrC'></small><noframes id='dVNrC'>

                  <i id='dVNrC'><tr id='dVNrC'><dt id='dVNrC'><q id='dVNrC'><span id='dVNrC'><b id='dVNrC'><form id='dVNrC'><ins id='dVNrC'></ins><ul id='dVNrC'></ul><sub id='dVNrC'></sub></form><legend id='dVNrC'></legend><bdo id='dVNrC'><pre id='dVNrC'><center id='dVNrC'></center></pre></bdo></b><th id='dVNrC'></th></span></q></dt></tr></i><div id='dVNrC'><tfoot id='dVNrC'></tfoot><dl id='dVNrC'><fieldset id='dVNrC'></fieldset></dl></div>
                1. <legend id='dVNrC'><style id='dVNrC'><dir id='dVNrC'><q id='dVNrC'></q></dir></style></legend>

                2. <tfoot id='dVNrC'></tfoot>