简体   繁体   English

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

[英]app crashes (only on Marshmallow(6.0.1)) when i send firebase push notification while app is on foreground but works fine when in background

Here is the code for the Firebase Messaging service: 这是Firebase Messaging服务的代码:

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

To show notification in foreground: 要在前台显示通知:

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

The issue is fixed. 该问题已解决。 The problem was that the app(Marshmallow) was not being able to extract the notification icon that I set. 问题是该应用程序(棉花糖)无法提取我设置的通知图标。 The app worked when I created a new image asset for the notification icon in the res directory. 当我在res目录中为通知图标创建新的图像资产时,该应用程序正常运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在前台在后台收到FCM通知时应用崩溃 - App Crashes when receiving FCM Notification on Foreground works on Background 应用程序在前台时收到的推送通知与应用程序在后台时收到的推送通知不同 - Push notification received while the app is in the foreground is different from push notification received when the app is in background Android 仅当应用程序处于前台时才播放推送通知声音,但当应用程序处于后台时不播放声音 - Android Push notification sound is played only when app is in foreground but not playing sound when app is in background 当应用程序不在后台或前台时,无法将通知推送到通知管理器 - When the app is not in background or foreground, not able push Notification to Notification manager 我的应用未运行时,如何发送类似Facebook的推送通知(背景/前景) - how can i send push notification like facebook while my app is not running(background/foreground) 当应用程序在后台时更新Firebase推送通知 - Updating Firebase push notification when app is in background 在Android中-当应用程序处于前台时如何防止Firebase推送通知? - In android - How to prevent Firebase push notification when app is in foreground? 应用程序在前台时推送通知(使用 Firebase 触发器) - Push notification when app is in foreground (using Firebase triggers) 前台应用程序抖动时未收到 Firebase 推送通知? - Firebase Push Notification not received when flutter app in foreground? 尝试在后台/前景中运行时应用程序崩溃,但适用于其他手机 - App crashes when trying to run in background/foreground but works for other phones
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM