Custom Notification Sound not working in Android Oreo

前端 未结 6 1671
闹比i
闹比i 2020-12-14 16:44
Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + \"://\" + context.getPackageName() + \"/\" + R.raw.notification_mp3);
            mBuilder.setSound(s         


        
6条回答
  •  天涯浪人
    2020-12-14 17:30

    Create a channel (I use this method in Application.clss to create the channel )

      public void initChannels(Context context) {
        if (Build.VERSION.SDK_INT < 26) {
            return;
        }
        NotificationManager notificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel channel = new NotificationChannel("default"/*CHANNEL ID*/,
                "CHANNEL_NAME",
                NotificationManager.IMPORTANCE_DEFAULT);
        channel.setDescription("Channel description");
        assert notificationManager != null;
        notificationManager.createNotificationChannel(channel);
    }
    

    And use this channel default while creating instance of NotificationCompat

     .... notificationBuilder = new NotificationCompat.Builder(this,"default") ....
    

提交回复
热议问题