首页 > 解决方案 > Android推送通知不起作用华为5.0棒棒糖设备如何修复它?

问题描述

您好朋友,我的推送通知不适用于华为 P10 Lite - Lollipop设备,而它在 6.0 设备上的工作是我的代码,请帮我修复它。这是我的通知代码:

public  void show(){
        Bitmap largeImage = BitmapFactory.decodeResource(getResources(),R.drawable.dog);

        PendingIntent pausePendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.ACTION_PAUSE_MUSIC"), 0);
        PendingIntent playPendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.ACTION_PLAY_MUSIC"), 0);
        PendingIntent nextPendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.NEXT_PLAY_MUSIC"), 0);
        PendingIntent perviousPendingIntent = PendingIntent.getBroadcast(this, 1, new Intent("music.playerforandroid.PERVIOUS_PLAY_MUSIC"), 0);
        Notification channel = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID_1)
                .setSmallIcon(R.drawable.ic_music)
                .setContentTitle(song.getTitle())
                .setContentText(song.getArtist())
                .setLargeIcon(largeImage)
                .addAction(R.drawable.ic_prev, "prev", perviousPendingIntent)
                .addAction(R.drawable.ic_play, "play", playPendingIntent)
                .addAction(R.drawable.ic_stat_name, "pause", pausePendingIntent)
                .addAction(R.drawable.ic_next, "next", nextPendingIntent)
                .setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle().
                        setShowActionsInCompactView(1, 2, 3))
                .build();
        mNotificationManagerCompat.notify(1, channel);
        }

这是我得到的错误?

E/MediaPlayer: Should have subtitle controller already set
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: music.playerforandroid, PID: 1305
    android.app.RemoteServiceException: Bad notification posted from package music.playerforandroid: Couldn't expand RemoteViews for: StatusBarNotification(pkg=music.playerforandroid user=UserHandle{0} id=1 tag=null score=0 key=0|music.playerforandroid|1|null|10117: Notification(pri=0 contentView=music.playerforandroid/0x109007f vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 category=transport actions=4 vis=PRIVATE))
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5538)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

标签: javaandroidpush-notification

解决方案


推荐阅读