Custom Notification Sound not working in Android Oreo

前端 未结 6 1673
闹比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

    try this:

    /**
     * show notification
     *
     * @param message
     */
    private static void showNotification(RemoteMessage message, Context baseContext) {
        Context context = baseContext.getApplicationContext();
        NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context.getApplicationContext());
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, null)
                .setSmallIcon(R.drawable.ic_logo_xxxdpi)
                .setContentTitle(message.getData().get(TITLE))
                .setContentText(message.getData().get(BODY))
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setAutoCancel(true)
                .setVibrate(new long[]{500, 500})
                .setLights(Color.RED, 3000, 3000)
                .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
                .setContentIntent(getPendingIntent(context, message));
        managerCompat.notify(getRandom(), builder.build());
    }
    

提交回复
热议问题