MediaStyle : RemoteServiceException: Bad notification posted from package

后端 未结 3 1339
轻奢々
轻奢々 2021-01-25 12:21

I\'m trying to create a notification media controller in my app using the code below which is working fine on all devices expect Huawei P8 Lite with An

3条回答
  •  伪装坚强ぢ
    2021-01-25 13:07

    Since some Huawei devices don't support MediaStyle you need to build notification without styling. I experienced this issue on this models Huawei P8 Lite and Huawei Y3II. So, check if device is huawei and SDK versions as mentioned and create a simple notification as below. This question helped me to find solution Strange allow/deny question on Huawei 5.1 phone when showing notification . Anyway, I hope helps someone

        boolean isLollipopHuawei = (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1 ||
                android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) && Build.MANUFACTURER.equalsIgnoreCase("HUAWEI");
    
    
        if (isLollipopHuawei) {
    
            builder
                    .setContentTitle(description.getTitle())
                    .setContentText(contentText)
                    .setOngoing(true)
                    .setContentIntent(createContentIntent())
                    .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                            R.drawable.mobi_plc))
    
                    .addAction(R.drawable.ic_previous_outline_notification,
                            this.service.getString(R.string.next_station),
                            MediaButtonReceiver.buildMediaButtonPendingIntent(
                                    this.service,
                                    PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS))
                    .addAction(R.drawable.ic_next_outline_notification,
                            this.service.getString(R.string.next_station),
                            MediaButtonReceiver.buildMediaButtonPendingIntent(
                                    this.service,
                                    PlaybackStateCompat.ACTION_SKIP_TO_NEXT))
    
                    .setSmallIcon(R.drawable.ic_stat)
    
                    .setAutoCancel(false);
        }
    

提交回复
热议问题