Firebase cloud messaging notification not received by device

前端 未结 20 1895
栀梦
栀梦 2020-11-28 23:58

I am having an issue with FireBase Cloud Messaging in which I get the Token from the device and send the notification test through the Google Firebase notification console h

相关标签:
20条回答
  • 2020-11-29 00:36

    In my case, I noticed mergedmanifest was missing the receiver. So I had to include:

     <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" />
                </intent-filter>
     </receiver>
    
    0 讨论(0)
  • 2020-11-29 00:40
    private void sendNotification(String message) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        int requestCode = 0;
        PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
        Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.URI_COLUMN_INDEX);
        NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentText(message)
                .setColor(getResources().getColor(R.color.colorPrimaryDark))
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("FCM Message")
                .setContentText("hello").setLargeIcon(((BitmapDrawable) getResources().getDrawable(R.drawable.dog)).getBitmap())
                .setStyle(new NotificationCompat.BigPictureStyle()
                        .bigPicture(((BitmapDrawable) getResources().getDrawable(R.drawable.dog)).getBitmap()))
                .setAutoCancel(true)
                .setSound(sound)
                .setContentIntent(pendingIntent);
    
        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, noBuilder.build());
    
    0 讨论(0)
  • 2020-11-29 00:42

    I faced the same issue of Firebase cloud messaging not received by device.

    In my case package name defined on Firebase Console Project was diferent than that the one defined on Manifest & Gradle of my Android Project.

    As a result I received token correctly but no messages at all.

    To sumarize, it's mandatory that Firebase Console package name and Manifest & Gradle matchs.

    You must also keep in mind that to receive Messages sent from Firebase Console, App must be in background, not started neither hidden.

    0 讨论(0)
  • 2020-11-29 00:43

    "You must also keep in mind that to receive Messages sent from Firebase Console, App must be in background, not started neither hidden." --- According to @Laurent Russier's comment.

    I never got any message from Firebase, until i put my app in the background.

    This is true only on usb connection for emulator you get notification in foreground as well

    0 讨论(0)
  • 2020-11-29 00:44

    You have placed your service outside the application tag. Change bottom to this.

    <service
        android:name=".NotificationGenie">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>
    
    </application>
    
    0 讨论(0)
  • 2020-11-29 00:45

    In my case, I manually killed some google play services and forgot about it.

    Later, I have to restart the device, after that I can receive notification without any problem.

    0 讨论(0)
提交回复
热议问题