java - android.app.RemoteServiceException : Bad notification posted on huawei Y6

标签 java android notifications huawei-mobile-services

我在运行 Android 5.1 的特定华为设备 (HUAWEI TIT-L01) 上发生崩溃

我使用 Google 找不到很多信息

堆栈跟踪:

android.app.RemoteServiceException: Bad notification posted from package 
com.myapp.test: Couldn't expand RemoteViews for: 
StatusBarNotification(pkg=com.myapp.test user=UserHandle{0} 
id=1 tag=null score=0 key=0|com.myapp.test|1|null|10693: 
Notification(pri=0 contentView=com.myapp.test/0x109007e 
vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 
category=transport actions=3 vis=PRIVATE))

代码(我没有写这个所以不要评判我):
private static void buildNotification(Notification.Action action) 
{
    final Notification.MediaStyle style = new Notification.MediaStyle();

    final Intent intent = new Intent(MyApplication.getAppContext(), MediaPlayerService.class);
    intent.setAction(ACTION_STOP);
    final PendingIntent pendingIntent = PendingIntent.getService(MyApplication.getAppContext(), 1, intent, 0);

    Bitmap coverImage = null;
    String bookTitle = "";
    String author = "";
    if (PlaybackUtils.INSTANCE.getCurrentBookPerformant() != null) {
        coverImage = CoverUtils.INSTANCE.getOnlineImage(PlaybackUtils.INSTANCE.getCurrentBookPerformant());
        bookTitle = PlaybackUtils.INSTANCE.getCurrentBookPerformant().getTitle();
        author = PlaybackUtils.INSTANCE.getCurrentBookPerformant().getCreator();
    } else if (PlaybackUtils.INSTANCE.getCurrentContentImpl() != null) {
        coverImage = CoverUtils.INSTANCE.loadDeviceCover(PlaybackUtils.INSTANCE.getCurrentContentImpl());
        bookTitle = PlaybackUtils.INSTANCE.getCurrentContentImpl().getTitle();
        author = PlaybackUtils.INSTANCE.getCurrentContentImpl().getAuthor();
    }

    final Notification.Builder builder = new Notification.Builder(MyApplication.getAppContext()).
            setSmallIcon(R.drawable.logo_statusbar)
            .setLargeIcon(coverImage)
            .setContentTitle(bookTitle)
            .setContentText(author)
            .setDeleteIntent(pendingIntent)
            .setStyle(style);

    builder.addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS));
    builder.addAction(action);
    builder.addAction(generateAction(android.R.drawable.ic_media_next, "Next", ACTION_NEXT));
    style.setShowActionsInCompactView(0, 1, 2);

    final NotificationManager notificationManager = (NotificationManager) MyApplication.getAppContext().getSystemService(Context.NOTIFICATION_SERVICE);
    final Notification build = builder.build();
    notificationManager.notify(1, build);
}

最佳答案

面临同样的问题。似乎华为的某些设备在通知中不支持标准 MediaStyle。只是不要添加MediaStyle如果你在华为跑。

final Notification.Builder builder = new Notification.Builder(MyApplication.getAppContext())
    .setSmallIcon(R.drawable.logo_statusbar)
    .setLargeIcon(coverImage)
    .setContentTitle(bookTitle)
    .setContentText(author)
    .setDeleteIntent(pendingIntent);
if (!Build.MANUFACTURER.toLowerCase(Locale.getDefault()).contains("huawei")) {
   builder.setStyle(style);
}
final Notification build = builder.build();
notificationManager.notify(1, build);

关于java - android.app.RemoteServiceException : Bad notification posted on huawei Y6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48733628/

相关文章:

java - 如何在数据点上添加点击监听器?

Android 自定义通知 setOnClickPendingIntent 不适用于低于 3.0 的版本。有办法让它发挥作用吗?

java - 使用for循环获取2个字符串之间的汉明距离

来自文本文件的 Java 输入参数

java - SpringMVC错误: The resource identified by this request is only capable of generating responses

java - 如何检查两个纬度和经度坐标之间的距离?

android - 具有不同大小项目Android的自定义ListView

swift - 如何从锁定屏幕访问设备电池电量

swift - 在前台而不是后台接收 Firebase 通知

java - Spring Cloud Streams 将数据条件转发到 Kafka 主题