Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Don';我们没有收到FCM通知_Android_Firebase_Kotlin_Notifications_Firebase Cloud Messaging - Fatal编程技术网

Android Don';我们没有收到FCM通知

Android Don';我们没有收到FCM通知,android,firebase,kotlin,notifications,firebase-cloud-messaging,Android,Firebase,Kotlin,Notifications,Firebase Cloud Messaging,我在项目中实施FCM时遇到问题。问题是,我像文档中那样实现FCM,但我没有收到测试通知。我有类似的项目和相同的实施,但它在另一个项目中有效,而不是在当前: 我的服务: class MyFirebaseMessagingService: FirebaseMessagingService() { override fun onMessageReceived(p0: RemoteMessage) { super.onMessageReceived(p0) Lo

我在项目中实施FCM时遇到问题。问题是,我像文档中那样实现FCM,但我没有收到测试通知。我有类似的项目和相同的实施,但它在另一个项目中有效,而不是在当前:

我的服务:

class MyFirebaseMessagingService: FirebaseMessagingService() {

    override fun onMessageReceived(p0: RemoteMessage) {
       super.onMessageReceived(p0)

        Log.d("RECEIVED", "MESSAGE RECEIVED")
        sendNotification(p0)
    }

    private fun sendNotification(remoteMessage: RemoteMessage){

        val intent = Intent(this, MainActivity::class.java)
        val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)

        val channelId = "fcm_channel"
        val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
        val notificationBuilder: NotificationCompat.Builder = NotificationCompat.Builder(
            this,
            channelId
        )
            .setSmallIcon(R.mipmap.ic_launcher_round)
            .setContentTitle(remoteMessage.notification?.title)
            .setContentText(remoteMessage.notification?.body)
            .setAutoCancel(true)
            .setSound(soundUri)
            .setContentIntent(pendingIntent)

        val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){

            val channel: NotificationChannel = NotificationChannel(channelId, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT)
            notificationManager.createNotificationChannel(channel)
        }

        notificationManager.notify(0, notificationBuilder.build())
    }

}
舱单:

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Складу ЗНО"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="ExtraText,GoogleAppIndexingWarning">

        <service
            android:name=".services.MyFirebaseMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>


你在firebase管理过你的项目吗?@mingchen,当然有