Android push notification is not working on 5.0 lollipop device?

1

Hello friends my push notification is not working on android 5.0 lollipop i tested this code on 6.0 work fine but not working on 5.0 huawei device here code what can i do now please help how to fixed this proble, i am stuck at this step i done almost all step i am beginner

   Bitmap largeImage = BitmapFactory.decodeResource(getResources(),R.drawable.musicicon);

                //Intent pauseIntent = new Intent("music.playerforandroid.ACTION_PAUSE_MUSIC");

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



package music.playerforandroid;

import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;

    public class App extends Application {
        public static final String  CHANNEL_ID_1 = "channel1";
        public static final String CHANNEL_NAME_1 = "FIRSTCHANNEL";

        @Override
        public void onCreate() {
            super.onCreate();

            createNotificationChannel();

        }

        private void createNotificationChannel() {

            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
                NotificationChannel channle1 = new NotificationChannel(
                        CHANNEL_ID_1,
                        CHANNEL_NAME_1,
                        NotificationManager.IMPORTANCE_HIGH

                );
                channle1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
                channle1.enableLights(true);

                NotificationManager manager = getSystemService(NotificationManager.class);
                manager.createNotificationChannel(channle1);
            }


        }


    }

and i am getting this error

E/MediaPlayer: Should have subtitle controller already set E/MediaPlayer: Should have subtitle controller already set E/AndroidRuntime: FATAL EXCEPTION: main Process: music.playerforandroid, PID: 22269 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|10112: 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)

java
android
push-notification
asked on Stack Overflow Mar 29, 2019 by maha songs • edited Mar 29, 2019 by maha songs

1 Answer

0

I recomend you using this. This is sending a notification from your server to the platform server and the platform server to google server that sends you the 'push-notification', you also can fiind a way to install this. Good Luck.

answered on Stack Overflow Mar 31, 2019 by Fabian Andrei

User contributions licensed under CC BY-SA 3.0