无法从 firebase 控制台发送通知

Failed to send notification from firebase console

This 是 firebase 的一些教程。我正在 Firebase 中注册应用程序,获取 google-services.json 文件,并将其粘贴到应用程序文件中,如教程中所示。也得到令牌。但是当我尝试从控制台发送通知时,状态为失败(我猜是 MismatchSenderId)。我正在插入从 FirebaseInstanceId.getInstance().getToken(); 获得的相同令牌。可能是什么问题?

p.s。当我向所有使用该应用程序的设备发送通知时,它也没有成功。

编辑: 清单文件

<!-- Adding Internet Permission -->

<uses-permission android:name="android.permission.INTERNET"/>
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <!--
        Defining Services
    -->
    <service
        android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>

    <service
        android:name=".MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>
</application>

可能是您没有为您的应用程序添加正确的 SHA1? 您可以按照 this tutorial 获取正确的 SHA1。然后在控制台 firebase 上选择项目设置,选择添加 SHA1。之后需要将google-services.json换成最新的

请检查是否满足以下所有条件。

  1. Update the SHA 1 finger print and package name in your console.
  2. Place a json configuration file from the developer console and place it under app directory [module level directory].
  3. Add these lines in the gradle files. a) Module gradle : apply plugin: 'com.google.gms.google-services' b) Project gradle : classpath 'com.google.gms:google-services:3.0.0'

希望对你有所帮助...