当应用程序在前台时发送Firebase推送通知时,应用程序崩溃(仅在棉花糖(6.0.1)上),但在后台运行时工作正常

时间:2018-11-20 14:21:16

标签: android firebase firebase-cloud-messaging

以下是Firebase Messaging服务的代码:

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

要在前台显示通知:

    private void showNotification(String title, String body) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        String NOTIFICATION_CHANNEL_ID = "com.shijan.qrscannerict.test";

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);

        notificationBuilder.setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL)
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.ict_logo)
                .setContentTitle(title)
                .setContentText(body)
                .setContentInfo("Info");

        notificationManager.notify(new Random().nextInt(), notificationBuilder.build());
    }

1 个答案:

答案 0 :(得分:0)

问题已解决。问题是该应用程序(棉花糖)无法提取我设置的通知图标。当我在res目录中为通知图标创建新的图像资产时,该应用程序正常运行。