Android Notification Not working on Android 6.0 (Marshmallow)

android, android-6.0-marshmallow, android-notifications, notifications

Solution

There are some changes in new notification. new `NotificationCompat.Builder(this)` is deprecated and need `NotificationChannel`for android oreo above. You can try this solution.

NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(mContext.getApplicationContext(), "notify_001");
        Intent ii = new Intent(mContext.getApplicationContext(), RootActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, ii, 0);

        NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
        bigText.bigText(verseurl);
        bigText.setBigContentTitle("Title");
        bigText.setSummaryText("Text in detail");

        mBuilder.setContentIntent(pendingIntent);
        mBuilder.setSmallIcon(R.mipmap.ic_launcher_round);
        mBuilder.setContentTitle("Your Title");
        mBuilder.setContentText("Your text");
        mBuilder.setPriority(Notification.PRIORITY_MAX);
        mBuilder.setStyle(bigText);

        NotificationManager mNotificationManager =
                (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel("notify_001",
                    "Channel human readable title",
                    NotificationManager.IMPORTANCE_DEFAULT);
            mNotificationManager.createNotificationChannel(channel);
        }

        mNotificationManager.notify(0, mBuilder.build());

Problem

I'm implementing local notification on Android and I have the problem that they are not appearing on Android 6.0 (Samsung S7). I was searching for solutions, but I coulnd't find anything for this problem. I have the icon in the proper res/drawable folder, also I have defined a notification title, text, ringtone (raw folder) but it's not showing up... There is my code: ``` Context acontext = getApplicationContext(); PackageManager pm = acontext.getPackageManager(); Intent notificationIntent = pm.getLaunchIntentForPackage(acontext.getPackageName()); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(acontext, 0, notificationIntent, 0); int notification_icon = acontext.getResources().getIdentifier("icon", "drawable", acontext.getPackageName()); int notificationID = 0; // Build notification Notification noti = new Notification.Builder(acontext) .setContentTitle("Title") .setContentText("Incoming text") .setSmallIcon(notification_icon) .setContentIntent(pendingIntent) .setLights(Color.RED, 1, 1) .build(); NotificationManager notificationManager = (NotificationManager) acontext.getSystemService(Context.NOTIFICATION_SERVICE); // hide the notification after its selected noti.sound = Uri.parse("android.resource://" + acontext.getPackageName() + "/raw/incoming"); noti.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(notificationID, noti); ``` Did anyone else experience this problem? Any help would be appreciated. Thank you.

Original source