【问题标题】:android.app.RemoteServiceException: Bad notification posted on huawei Y6android.app.RemoteServiceException: 华为 Y6 上发布的错误通知
【发布时间】:2018-03-28 01:06:05
【问题描述】:

我在运行 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);
}

【问题讨论】:

  • 你确定这段代码触发了那个异常吗?我看不到你在哪里使用RemoteViews
  • 我很确定。 MediaStyle 确定通知的视图层次结构
  • Android 本身的 Notification$MediaStyle 中的几个方法返回一个 RemoteViews 对象。我的猜测是它在 makeMediaContentView 方法中
  • 我在同一台设备上遇到了同样的问题!这似乎是由 MediaStyle 引起的,但我还没有找到解决方案。你并不孤单!
  • 谢谢,如果您有新发现请告诉我!

标签: java android notifications huawei-mobile-services


【解决方案1】:

面临同样的问题。似乎华为的某些设备在通知中不支持标准 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);

【讨论】:

  • 这对我有用,但由于某种原因,它会在通知上显示一条消息,询问我是否要允许应用推送通知消息,你以前见过吗? stackoverflow.com/q/54874512/704836
  • @casolorz 这可能是华为 UI 特有的。也许他们已经为通知实现了一层,以要求用户允许来自特定应用程序的通知。这与推送消息(例如谷歌推送消息)不同。不幸的是,我没有任何华为设备可以测试。
  • 是的,这是我的想法,只是找不到任何相关信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 1970-01-01
  • 2018-06-15
  • 2014-10-08
相关资源
最近更新 更多