1
votes

MediaStyle: RemoteServiceException: notification incorrecte publiée à partir du package

J'essaie de créer un contrôleur multimédia de notification dans mon application en utilisant le code ci-dessous qui fonctionne correctement sur tous les appareils sauf Huawei P8 Lite avec Android 5.0 , je obtenir ce journal des erreurs du laboratoire de test Firebase:

android.app.RemoteServiceException: mauvaise notification postée depuis package maa.app_app: impossible de développer RemoteViews pour: StatusBarNotification (pkg = maa.app_app user = UserHandle {0} id = 555 tag = score nul = 10 clé = 0 | maa.app_app | 555 | null | 10108: Notification (pri = 1 contentView = maa.app_app / 0x109007f vibrate = null sound = null par défaut = 0x0 flags = 0x62 color = 0xffbfbfbf category = transport actions = 2 vis = PUBLIC)) EXCEPTION FATALE: Processus principal: maa.app_app, PID: 18793 android.app.RemoteServiceException: mauvaise notification publiée depuis package maa.app_app: impossible de développer RemoteViews pour: StatusBarNotification (pkg = maa.app_app user = UserHandle {0} id = 555 tag = score nul = 10 clé = 0 | maa.app_app | 555 | null | 10108: Notification (pri = 1 contentView = maa.app_app / 0x109007f vibrate = null sound = null par défaut = 0x0 flags = 0x62 color = 0xffbfbfbf category = transport actions = 2 vis = PUBLIC)) à android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1534) à android.os.Handler.dispatchMessage (Handler.java:102) à android.os.Looper.loop (Looper.java:135) sur android.app.ActivityThread.main (ActivityThread.java:5538) à java.lang.reflect.Method.invoke (Méthode native) à java.lang.reflect.Method.invoke (Method.java:372) à com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:960) à com.android.internal.os.ZygoteInit.main (ZygoteInit.java:755)

voici mon code:

void startNotify(Context context, String playbackStatus, String title) {
    String titlesonge;
    String artist;
    try {
        titlesonge = StringUtils.substringBefore(title, " - ");
        artist = StringUtils.substringAfter(title, " - ");
    } catch (Exception e) {
        titlesonge = title.substring(0, title.indexOf(" - "));
        artist = title.substring(title.lastIndexOf(" - ") - 1);
    }
    int icon = R.drawable.ic_pause_white;
    Intent playbackAction = new Intent(service, RadioService.class);
    playbackAction.setAction(RadioService.ACTION_PAUSE);
    PendingIntent action = PendingIntent.getService(service, 1, playbackAction, 0);
    if (playbackStatus.equals(PlaybackStatus.PAUSED)) {
        icon = R.drawable.ic_play_white;
        playbackAction.setAction(RadioService.ACTION_PLAY);
        action = PendingIntent.getService(service, 2, playbackAction, 0);

    }
    Intent stopIntent = new Intent(service, RadioService.class);
    stopIntent.setAction(RadioService.ACTION_STOP);
    PendingIntent stopAction = PendingIntent.getService(service, 3, stopIntent, 0);

    Intent intent = new Intent(service, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_SINGLE_TOP |
            Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(service, 0, intent, 0);
    notificationManager.cancel(NOTIFICATION_ID);
    String PRIMARY_CHANNEL = "PRIMARY_CHANNEL_ID";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager manager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
        String PRIMARY_CHANNEL_NAME = "PRIMARY";
        NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL, PRIMARY_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        if (manager != null) {
            manager.createNotificationChannel(channel);
        }
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(service, PRIMARY_CHANNEL)
            .setAutoCancel(false)
            .setContentTitle(titlesonge)
            .setContentText(artist)
            .setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.largeicon))
            .setContentIntent(pendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setSmallIcon(R.drawable.smallwidth)
            .setColor(ContextCompat.getColor(context, R.color.colorneeded))
            .addAction(icon, "pause", action)
            .addAction(R.drawable.ic_stop_white, "stop", stopAction)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setWhen(System.currentTimeMillis())
            .setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
                    .setMediaSession(service.getMediaSession().getSessionToken())
                    .setShowActionsInCompactView(0, 1)
                    .setShowCancelButton(true)
                    .setCancelButtonIntent(stopAction));
    service.startForeground(NOTIFICATION_ID, builder.build());
}

quelqu'un peut-il m'aider à résoudre ce problème


0 commentaires

3 Réponses :


4
votes

Pour une raison quelconque, les appareils Huawei équipés d'Android 5.0 se bloquent lors de l'utilisation de la méthode .setStyle () , vous avez donc deux possibilités:

1 - détecter la fabrication de l'appareil si c'est Huawei ou non, et avoir un Android 5.0 ou inférieur ou non

void exoPlayerNotification(Context context, SimpleExoPlayer exoPlayer, String title) {
    String titlesonge;
    String artist;
    try {
        titlesonge = StringUtils.substringBefore(title, " - ");
        artist = StringUtils.substringAfter(title, " - ");
    } catch (Exception e) {
        titlesonge = title.substring(0, title.indexOf(" - "));
        artist = title.substring(title.lastIndexOf(" - ") - 1);
    }
    String finalArtist = artist;
    String finalTitlesonge = titlesonge;
    mPlayerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
            context,
            "PRIMARY_CHANNEL_ID",
            R.string.plaza,
            NOTIFICATION_ID,
            new PlayerNotificationManager.MediaDescriptionAdapter() {
                @Override
                public String getCurrentContentTitle(Player player) {
                    return finalArtist;
                }

                @Nullable
                @Override
                public PendingIntent createCurrentContentIntent(Player player) {
                    Intent intent = new Intent(service, MainActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    return PendingIntent.getActivity(service, 0, intent,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                }

                @Override
                public String getCurrentContentText(Player player) {
                    return finalTitlesonge;
                }

                @Nullable
                @Override
                public Bitmap getCurrentLargeIcon(Player player, PlayerNotificationManager.BitmapCallback callback) {
                    return BitmapFactory.decodeResource(service.getResources(), R.drawable.largeicon);
                }

                @Nullable
                @Override
                public String getCurrentSubText(Player player) {
                    return null;
                }
            }
    );
    mPlayerNotificationManager.setUseNavigationActions(false);
    mPlayerNotificationManager.setFastForwardIncrementMs(0);
    mPlayerNotificationManager.setRewindIncrementMs(0);
    mPlayerNotificationManager.setColorized(true);
    mPlayerNotificationManager.setColor(0xFFEEEEEE);
    mPlayerNotificationManager.setUseChronometer(true);
    mPlayerNotificationManager.setOngoing(true);
    mPlayerNotificationManager.setPriority(NotificationCompat.PRIORITY_MAX);
    mPlayerNotificationManager.setUsePlayPauseActions(true);
    mPlayerNotificationManager.setSmallIcon(R.drawable.smallwidth);
    mPlayerNotificationManager.setNotificationListener(new PlayerNotificationManager.NotificationListener() {
        @Override
        public void onNotificationStarted(int notificationId, Notification notification) {
            service.startForeground(notificationId, notification);
        }

        @Override
        public void onNotificationCancelled(int notificationId) {
            service.stopSelf();
            cancelNotify();
        }
    });
    mPlayerNotificationManager.setPlayer(exoPlayer);
}

2 - Utilisez plutôt PlayerNotificationManager

public boolean isLolliPopHuawei() {
    return (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");
}


1 commentaires

Je ne suis pas sûr que PlayerNotificationManager résoudrait le problème; il passe également inconditionnellement un MediaStyle à setStyle () . github.com/google/ExoPlayer/blob/...



1
votes

Étant donné que certains appareils Huawei ne prennent pas en charge MediaStyle, vous devez créer une notification sans style. J'ai rencontré ce problème sur ces modèles Huawei P8 Lite et Huawei Y3II. Donc, vérifiez si l'appareil est les versions huawei et SDK comme mentionné et créez une notification simple comme ci-dessous. Cette question m'a aidé à trouver une solution Étrange autoriser / refuser la question sur le téléphone Huawei 5.1 lors de l'affichage de la notification . Quoi qu'il en soit, j'espère aider quelqu'un

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


0 commentaires

0
votes

J'ai eu le même problème et la cause principale n'a pas pu définirStyle, il ne donnait cette exception que dans Huawei P8 Lite, pas sur d'autres appareils.

Donc, ce que je devais faire était de vérifier si l'appareil actuel était Android version 5.0 et son fabricant est Huawei et supprimez la propriété setStyle. veuillez vérifier le code ci-dessous

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 (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1 || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {

            if (isLollipopHuawei) {

                return builder
                        .addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", Constants.ACTION_PREVIOUS))
                        .addAction(action)
                        .addAction(generateAction(android.R.drawable.ic_media_next, "Next", Constants.ACTION_NEXT))
                        .setSmallIcon(R.mipmap.vpicon_grayscale)
                        .setContentTitle(getSongDataHelper().getTitle())
                        .setContentIntent(pendingIntent)
                        .setContentText(getSongDataHelper().getAlbum())
                        .setLargeIcon(getSongDataHelper().getAlbumArt())
                        //.setColor(color)
                      /*  .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
                                .setShowActionsInCompactView(0, 1, 2)
                                .setMediaSession(mMediaSession.getSessionToken()))*/
                        .build();
            } else {
                return builder
                        .addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", Constants.ACTION_PREVIOUS))
                        .addAction(action)
                        .addAction(generateAction(android.R.drawable.ic_media_next, "Next", Constants.ACTION_NEXT))
                        .setSmallIcon(R.mipmap.vpicon_grayscale)
                        .setContentTitle(getSongDataHelper().getTitle())
                        .setContentIntent(pendingIntent)
                        .setContentText(getSongDataHelper().getAlbum())
                        .setLargeIcon(getSongDataHelper().getAlbumArt())
                        //.setColor(color)
                        .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
                                .setShowActionsInCompactView(0, 1, 2)
                                .setMediaSession(mMediaSession.getSessionToken()))
                        .build();
            }
        }


0 commentaires