使用release-apk推送无法在Android 7.0(FCM)上运行的通知

时间:2018-05-31 09:21:40

标签: android firebase push-notification firebase-cloud-messaging

我的Android应用程序在商店中存在,其推送通知在>上突然停止工作7.0 android os。

依赖关系:

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

通知构建器代码:

通知经理:

   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);
        }
    }

通知建筑商:

                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());

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

请帮忙。

3 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

尝试替换:

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

使用最新更新(基于this url):

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

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

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

答案 2 :(得分:0)

从代码中可以看出,创建的NotificationChannel未通过进入NotificationCompat.Builder,因此您遇到此问题,您可以从文档hereHere是Google提供的通知示例。如果您想了解更多相关信息,请参阅docs