android - 为什么 FirebaseMessagingService.onMessageReceived() 没有被调用?

标签 android firebase firebase-cloud-messaging

在我的 android 项目中,我包括了 Firebase 云消息传递。我在 SDK 21 (Android 5) 上。

我的 Intent 是重写 MyFirebaseMessagingServiceonMessageReceived() 方法以捕获 Firebase 发送的方法并创建我自己的通知。

但似乎 onMessageReceived 无论如何都不会被调用。我按照 Android Studio 的内置说明来实现 firebase 并且使用 firebase 控制台进行测试实际上确实发送了我的测试设备收到的消息。

所以我的问题是,我是不是忘了实现某些东西?我有我的自定义 FirebaseMessagingService,一个用于在通知中执行操作的 BroadcastReceiver 和一个为 >= 26 创建和处理 SDK 的通知 channel 的 Application 类.

这是我的 list 文件的一部分:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
    android:name=".Networking.Firebase.FireBaseApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Activities.MainActivity"/>
    <activity
        android:name=".Activities.SplashActivity"
        android:noHistory="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

    </activity>
    <service android:name=".Networking.Firebase.PushMessageService" />
    <receiver android:name=".Networking.Firebase.PushReceiver"/>
</application>

最佳答案

class MyFirebaseMessagingService : FirebaseMessagingService() {

    override fun onMessageReceived(message: RemoteMessage?) {
        super.onMessageReceived(message)

            //TODO  Your Code

        }
    }
}


<!-- Firebase Notifications Service -->
        <service
            android:name=".MyFirebaseMessagingService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <!--
     Set custom default icon. This is used when no icon is set for incoming notification messages.
        -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_notification" />
        <!--
             Set color used with incoming notification messages. This is used when no color is set for the incoming
             notification message. 
        -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorAccent" />

关于android - 为什么 FirebaseMessagingService.onMessageReceived() 没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53615599/

相关文章:

android - 由 : android. database.sqlite.SQLiteException : no such table while compiling: SELECT FROM. 引起。

javascript - 如何避免 Firebase/Cloud Firestore 中的重复数据

firebase - SSR Hydration Vue js Nuxt

android - 我的 android 应用程序无法从 python 接收 fcm 消息

Android Logcat 获取空字符串时的行为非常奇怪

java - 通过可点击的 ListView 将 firebase 数据从一个 Activity 传递到另一个 Activity

firebase - Firebase 是否会影响生产应用程序的性能

ios - 在前台 ios 应用程序中没有收到 FCM 消息

java - 如何将 blob 转换为 .png 并通过 firebase 通知发送?

c# - Kindle Fire 视频流式传输崩溃