Sound Notification on Android

Asked 2 years ago, Updated 2 years ago, 34 views

I used the new NotificationCompat builder. It vibrates and displays LED notifications, but I can't make the notification sound. If you look at the Android document, you can style it however you want.

builder.setStyle(new NotificationCompat.InboxStyle()); You can't make sounds?

NotificationCompat.Builder builder =  
        new NotificationCompat.Builder(this)  
        .setSmallIcon(R.drawable.ic_launcher)  
        .setContentTitle("Notifications Example")  
        .setContentText("This is a test notification");  


Intent notificationIntent = new Intent(this, MenuScreen.class);  

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,   
        PendingIntent.FLAG_UPDATE_CURRENT);  

builder.setContentIntent(contentIntent);  
builder.setAutoCancel(true);
builder.setLights(Color.BLUE, 500, 500);
long[] pattern = {500,500,500,500,500,500,500,500,500};
builder.setVibrate(pattern);
builder.setStyle(new NotificationCompat.InboxStyle());
// // Add as notification  
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);  
manager.notify(1, builder.build());  

android android-notifications

2022-09-22 22:24

1 Answers

Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); builder.setSound(alarmSound); I think you forgot this code.


2022-09-22 22:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.