2

I'm having crashes on a specific huawei device (HUAWEI TIT-L01) running Android 5.1

I'm not finding alot of information by using Google

stacktrace:

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))

code (I didn't wrote this so don't judge me) :

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);
}
DennisVA
  • 2,068
  • 1
  • 25
  • 35
  • Are you sure this code is triggering that exception? I do not see where you are using a `RemoteViews`. – CommonsWare Oct 16 '17 at 13:30
  • i'm pretty sure. the MediaStyle determines the view hierarchy of the notification – DennisVA Oct 16 '17 at 13:33
  • in the Notification$MediaStyle in Android itself several methods return a RemoteViews object. My guess is that its in the makeMediaContentView method – DennisVA Oct 16 '17 at 14:03
  • I'm having the same problem on the same device! It seems to be caused by the MediaStyle, but I haven't found a solution. You are not alone! – Alex Meuer Nov 13 '17 at 16:13
  • Thanks, please let me know if you find anything new! – DennisVA Nov 14 '17 at 07:50

1 Answers1

8

Faced with same issue. It seems like some devices from Huawei doesn't support standard MediaStyle in notification. Just don't add MediaStyle if you run in Huawei.

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);
Taryn
  • 242,637
  • 56
  • 362
  • 405
  • This works for me but for some reason it shows a message on the notification asking me if I want to allow the app to push notification messages, have you seen that before? https://stackoverflow.com/q/54874512/704836 – casolorz Feb 26 '19 at 02:57
  • @casolorz That's might be Huawei UI specific. Maybe they have implemented one more layer for notifications to ask users to allow notifications from specific app. That's not the same as push messages (e.g. google push messages). Unfortunately I don't have any Huawei device to test that. – Vitalii Cherniak Feb 26 '19 at 16:01
  • Yeah that is my thinking just can't find anything about it. – casolorz Feb 26 '19 at 17:09