java - Android Nougat 上的错误通知 : Couldn't expand RemoteViews for: StatusBarNotification.

标签 java android android-notifications onesignal android-7.0-nougat

我使用 OneSignal SDK 来显示通知。 我在 OneSignalPushService.java 中执行此操作。

OneSignalPushService.java:

public class OneSignalPushService extends NotificationExtenderService {

    @Override
    protected boolean onNotificationProcessing(OSNotificationReceivedResult notification) {

        if (!TinyDbWrap.getInstance().isPushEnabled()) {
            KLog.d(this.getClass().getSimpleName(), "Notification will not displayed");
            return true;
        }

        OverrideSettings overrideSettings = new OverrideSettings();
        overrideSettings.extender = new NotificationCompat.Extender() {
            @Override
            public NotificationCompat.Builder extend(NotificationCompat.Builder notificationBuilder) {
                notificationBuilder.setDefaults(0);
                notificationBuilder.setContentTitle(getApplicationContext().getResources().getString(R.string.app_name));

                boolean is_in_silent_mode = false; /*or true by user's settings in app*/
                /*TinyDbWrap.getInstance()... - it stores user's settings*/
                KLog.d(OneSignalPushService.class.getSimpleName(), "Notification isSoundPushEnabled: " + TinyDbWrap.getInstance().isSoundPushEnabled());
                if (!is_in_silent_mode && TinyDbWrap.getInstance().isSoundPushEnabled()) {
                    notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                } else {
                    notificationBuilder.setSound(null);
                }

                KLog.d(OneSignalPushService.class.getSimpleName(), "Notification isVibrationPushEnabled: " + TinyDbWrap.getInstance().isVibrationPushEnabled());
                if (!is_in_silent_mode && TinyDbWrap.getInstance().isVibrationPushEnabled()) {
                    notificationBuilder.setVibrate(new long[]{0, 100, 200, 300, 400});
                } else {
                    notificationBuilder.setVibrate(new long[]{0});
                }

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    notificationBuilder.setColor(ContextCompat.getColor(getApplicationContext(), R.color.bg_first_item_white_scheme));
                }
                notificationBuilder.setLights(ContextCompat.getColor(getApplicationContext(), R.color.time_white_sheme), 500, 500);
                return notificationBuilder;
            }
        };

        OSNotificationDisplayedResult result = displayNotification(overrideSettings);
        if (result != null) {
            KLog.d(OneSignalPushService.class.getSimpleName(), "Notification displayed with id: " + result.androidNotificationId);
        }

        return true;
    }

}

这适用于我所有的设备,但是:

我仅在装有 Android Nougat 的设备上收到有关 Crashlytics 的大量此类问题:

Fatal Exception: android.app.RemoteServiceException: Bad notification posted from package my.package: Couldn't expand RemoteViews for: StatusBarNotification(pkg=my.package user=UserHandle{0} id=-1542711428 tag=null key=0|my.package|-1542711428|null|10184: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x19 color=0xff56a0d3 vis=PUBLIC semFlags=0x0 semPriority=0)) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1813) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6776) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

不幸的是,我无法在装有 Android Nougat 的设备上重现此问题,以了解如何消除它。

我试图更改通知图标等图形资源,以清理项目以遵循this advice .

当我发布新版本的应用程序后,我注意到有这个问题的设备数量增加了一周,这些数字减少到零。

这个问题还有reported to Googledevelopers of OneSignal SDK .

我正在寻找可以帮助消除此问题的任何解决方法、任何想法或建议。

最佳答案

我认为发生此崩溃是因为您的通知包含对 PendingIntent 包中图标的整数引用,并且该整数稍后在发布到 NotificationManager 时被引用。

在获取整数引用和挂起 Intent 之间,更新了应用程序并且更改了所有可绘制对象引用。用于引用正确可绘制对象的整数现在引用了不正确的可绘制对象或根本没有(根本没有 - 导致此崩溃)

这是由

证明的

I noticed that number of devices with this issue increase for a week when I release a new version of the app later these numbers decrease to zero.

作为一种解决方案,您可以在更新应用程序后重建所有通知。

关于java - Android Nougat 上的错误通知 : Couldn't expand RemoteViews for: StatusBarNotification.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46873429/

相关文章:

java - Android Webview 应用程序上下文

java - 在java中使用jdbc、results.getString(1)或results.getString ("field_name"哪个更有效)

android - 如何在 Android Wear 中为 2D Pickers 添加页面点?

Android - 从网络浏览器返回时防止重新创建 Activity

android - 通知状态栏文字

android - Firebase 云消息传递错误 : Couldn't resolve host 'fcm.googleapis.com'

Android:如果将 Activity 带回屏幕,Notification 的 PendingIntent 不会触发 onCreate()

Java方法: Integer contains 1

java - Android:无法制作大量相同类型的 Activity

android - Firebase RecyclerView - 添加新项目时滚动动画