0

I am trying to create a notification channel with High Priority but the channel created has "sound off" and "floating notification" is off. I am not sure if I should include any special permission to achieve it.

I have tried creating notification channel with high priority. Have tried changing the channel id and reinstalling the app. I am trying it in a complete new application.

// To create channel

private void createNotificatnChennal() {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        {
            NotificationChannel chennal1 = new NotificationChannel(
                    chennal_01_id,
                    chennal_01_name,
                    NotificationManager.IMPORTANCE_HIGH
            );

            AudioAttributes att = new AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .setUsage(AudioAttributes.USAGE_ALARM)
                    .build();


            chennal1.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),att);
            chennal1.setDescription("Test channel one");

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

// display notification

    String title = "Test title";
    String body = "Test Msg";

    Notification notification = new NotificationCompat.Builder(MainActivity.this,chennal_01_id)
            .setSmallIcon(R.drawable.ic_icon)
            .setContentText(body)
            .setContentTitle(title)
            .setPriority(NotificationCompat.PRIORITY_MAX)
            .setCategory(NotificationCompat.CATEGORY_MESSAGE)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setVibrate(new long[0])
            .setDefaults(Notification.DEFAULT_ALL)
            .build();

    notifManager.notify(1,notification);

I want my notification to make sound and popup at the top.

But for now its not making sound and doesn't popup for version >= 8.0, and for < 8.0 its making sound but no popup.

Vasanth S
  • 19
  • 6
  • would you care to go through here https://github.com/Hemen07/Nimbus-Todo-pad-Reminder/blob/master/app/src/main/java/com/redfox/nimbustodo/util/alarm_util/UtilNotification.java different version for M, N and O – hemen Dec 31 '18 at 12:45
  • Sorry its not working.. still the sound is off in channel settings.. But if i check the importance by getImportance() it returns 4. Kindly assist.. And also it works well as expected in emulator.. – Vasanth S Jan 01 '19 at 04:14
  • https://stackoverflow.com/questions/31398381/how-to-add-custom-notification-sound-in-android, go on to this – hemen Jan 02 '19 at 10:25

0 Answers0