2

I really need your help. Currently, I am working on notification module in my app. My problem is that notification works under Oreo, but not working on Oreo and Pie. I am using mi (Xiaomi) devices and below is my code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = notificationManager.getNotificationChannel(CHANNEL_ID);
        if (channel == null){
            channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
                channel.enableLights(true);
                channel.enableVibration(true);
                channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
                channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
                AudioAttributes att = new AudioAttributes.Builder()
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                        .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                        .build();
                channel.setSound(Uri.parse(sound), att);
                notificationManager.createNotificationChannel(channel);
            }
            mBuilder = new NotificationCompat.Builder(mContext, CHANNEL_ID);
            mBuilder.setSmallIcon(icon)
                    .setTicker(message)
                    .setWhen(System.currentTimeMillis())
                    .setAutoCancel(true)
                    .setContentTitle(title)
                    .setContentIntent(resultPendingIntent)
                    .setSound(Uri.parse(sound))
                    .setLights(0xff00ff00, 500, 500)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(notificationVO.getMessage()))
                    .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
                    .setContentText(message)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        }

The detail of my problem is that notification is receiving by phone when the condition is turned on but no sound, vibration. in lock screen the notification not showing, no led, no vibration, and no sound.

Is there anyone who know how to solve this? Thank you all and I am really appreciate your help

Masoud Maleki
  • 813
  • 6
  • 13
Tetsu
  • 83
  • 1
  • 7
  • Please push whole your code for setting up notification (like where calling mBuilder.build() and etc)? – Masoud Maleki Jan 19 '20 at 10:58
  • I am using this link as my reference: https://stackoverflow.com/a/46991229/11851867 – Tetsu Jan 19 '20 at 11:13
  • Can you test it on another android oreo device other than Xiaomi? – Masoud Maleki Jan 19 '20 at 12:15
  • Unfortunately i dont have another oreo devices than xiaomi. I think i will close this question and mark your answer as accepted, since currently i am decided to implement your solution about direct user to notification settings while i will keep experiment and wait update from google and other developers to optimize notification development for all android devices starting from oreo. Thank you for your solution and i am really appreciate it. – Tetsu Jan 19 '20 at 12:24
  • Also try to use tips like [this](https://c.mi.com/thread-1545043-1-0.html) to see if it can fix your Xiaomi notification problem? – Masoud Maleki Jan 19 '20 at 12:26
  • Alright, thank you @MasoudMaleki, glad with your help – Tetsu Jan 19 '20 at 12:28

1 Answers1

0

Short answer: Use another channel id and see if it is working.

More explained: The settings of android notification channels can not be changed after they are created (But the user can change them from app notification settings). So if you want to use new settings for your channel after once created, you have three choices:

  1. Use another channel id

  2. Remove old channel and create a new channel with old channel id, as explained here.

  3. Send user to notification settings for changing settings, as explained here.

Masoud Maleki
  • 813
  • 6
  • 13
  • Alright, i will try it first and notify the result as soon as possible – Tetsu Jan 19 '20 at 09:58
  • I have been try user another channel id, uninstall and reinstall the app. But the problem still not solved yet, is there any other solution that i can do without ask the user to manually setup the settings? – Tetsu Jan 19 '20 at 10:08
  • Revised: I have been try use another channel id, uninstall and reinstall the app. But the problem still not solved yet, is there any other solution that i can do without ask the user to manually setup the settings? – Tetsu Jan 19 '20 at 10:14