кастомный звук для уведомлений в 8.0 андроиде - PullRequest
0 голосов
/ 20 ноября 2018

Я пытаюсь воспроизвести пользовательский звук для своих уведомлений. Я бы искал много, но не повезло, здесь мой код уведомления.

 NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    inboxStyle.addLine(message);

    Notification notification;
    mBuilder = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound  )
            .setStyle(inboxStyle)
            .setNumber(1)
            .setColor(mContext.getResources().getColor(R.color.blue))
            .setChannelId("my_channel_01")
            .setWhen(System.currentTimeMillis())
            .setSmallIcon(R.mipmap.app_icon)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))

           .setContentText(message);

    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            String CHANNEL_ID = "my_channel_01";// The id of the channel.
            AudioAttributes audioAttributes = new AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .setUsage(AudioAttributes.USAGE_ALARM)
                    .build();
            CharSequence name = mContext.getString(R.string.app_name);// The user-visible name of the channel.
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
            mChannel.setShowBadge(true);

            mChannel.setSound(alarmSound,audioAttributes);
            notificationManager.createNotificationChannel(mChannel);
            notificationManager.notify(Config.NOTIFICATION_ID, mBuilder.build());
        } 

уведомление появляется, но без звука.

...