使用release-apk推送通知不适用于Android 7.0(FCM)

时间:2021-05-23 16:22:52

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

我的Android应用程序在商店上运行,其推送通知在> 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.

在调试apk它工作我检查但生产(release_apk)它没有显示通知。

Please help in this.

请帮忙。

3 个解决方案

#1


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.

从代码中很明显,您创建的NotificationChannel未传递到NotificationCompat.Builder,因此您遇到此问题,您可以从此处的文档中了解它。以下是Google提供的通知示例。如果您想了解更多相关信息,请参阅文档。

#2


0  

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

确保已将发布证书的SHA1添加到Firebase项目的“项目设置”/“常规”页面中。

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

对于每个应用程序,您可以添加多个SHA1,您应该包括调试和发布证书。

#3


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:

并确保您在最新版本中使用Google Play服务:

classpath 'com.google.gms:google-services:4.0.1'

#1


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.

从代码中很明显,您创建的NotificationChannel未传递到NotificationCompat.Builder,因此您遇到此问题,您可以从此处的文档中了解它。以下是Google提供的通知示例。如果您想了解更多相关信息,请参阅文档。

#2


0  

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

确保已将发布证书的SHA1添加到Firebase项目的“项目设置”/“常规”页面中。

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

对于每个应用程序,您可以添加多个SHA1,您应该包括调试和发布证书。

#3


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:

并确保您在最新版本中使用Google Play服务:

classpath 'com.google.gms:google-services:4.0.1'