4

My android app is live on the store and its push notification stopped working suddenly on > 7.0 android os.

Dependencies :

'com.google.firebase:firebase-core:10.2.0'    
'com.google.firebase:firebase-messaging:10.2.0'

Notification builder code :

NOTIFICATION MANAGER :

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

            notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            String id = "projectname";
            // The user-visible name of the channel.
            CharSequence name = "projectname";
            // The user-visible description of the channel.
            int importance = NotificationManager.IMPORTANCE_MAX;
            NotificationChannel mChannel = new NotificationChannel(id, name, importance);
            // Configure the notification channel.
            mChannel.enableLights(true);
            mChannel.setLightColor(Color.RED);
            notificationManager.createNotificationChannel(mChannel);

        }else{
            notificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        }
    }

NOTIFICATION BUILDER :

                NotificationCompat.Builder notificationBuilder = new
                        NotificationCompat.Builder(this);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    notificationBuilder.setSmallIcon(R.drawable.ic_launcher_transparent);
                } else {
                    notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
                }
                notificationBuilder
                        .setContentTitle("Projectname")
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(intent.getStringExtra("gcm.notification.body")))
                        .setContentText(intent.getStringExtra("gcm.notification.body"))
                        .setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND).setSound(soundUri)
                        .setContentIntent(pendingIntent).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

createNotificationManager();
notificationManager.notify(id, notificationBuilder.build());

In debug apk it is working i checked but with the production (release_apk) it is not showing notification.

Please help in this.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Parvindra Singh
  • 237
  • 3
  • 13

3 Answers3

1

Ensure that you have added the SHA1 of your release certificate into the Project Settings/General page for your Firebase project.

For each app you can add multiple SHA1's and you should include both your debug and release certificates.

CodeChimp
  • 4,745
  • 6
  • 45
  • 61
0

Try to replace:

'com.google.firebase:firebase-core:10.2.0'    
'com.google.firebase:firebase-messaging:10.2.0'

With latest update (based on this url):

implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-messaging:17.0.0'

And make sure that you are using google play services in latest version too:

classpath 'com.google.gms:google-services:4.0.1'
Paraskevas Ntsounos
  • 1,755
  • 2
  • 18
  • 34
  • if i will update my dependencies then i need to update my notification builder code too right ? It will not effect any lower version support right ? please suggest if possible. – Parvindra Singh May 31 '18 at 09:54
  • @ParvindraSingh try after update dependencies a push notification and check if it works maybe doesnt need to update your code, and tell us what happend – Paraskevas Ntsounos May 31 '18 at 09:55
  • No @paraskevas still struggling , I have used the War_hero solution and send the channel also , but after create release build notification not working. I will try some another solution. – Parvindra Singh Jun 01 '18 at 05:20
0

From the code it is evident that the NotificationChannel that you have created is not passed into the NotificationCompat.Builder hence you are facing this issue, you can read about it from the docs here. Here is an example of the notification given by google. If you want to read more about this refer the docs.

Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52