How to set notification with custom sound in android

前端 未结 6 1897

I copied the mp3 (kalimba.mp3) file into the raw folder in the res folder. But when the notification is triggered it produces the default sound.

6条回答
  •  孤独总比滥情好
    2020-11-29 03:35

    I have implemented this way to set custom Notification sound in my app.

      int notificationID=001;
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    
            mBuilder.setSmallIcon(R.drawable.room);
            mBuilder.setContentTitle("Room Rent , Pay Room Rent");
            mBuilder.setContentText("Hi, Its time to pay your Room Rent!");
            mBuilder.setAutoCancel(true);
            mBuilder.setColor(getResources().getColor(R.color.colorViolet));
            mBuilder.setSound(Uri.parse("android.resource://com.roommanagement.app/" + R.raw.notification_sound));
    
            if (mNotificationManager!=null){
                mNotificationManager.notify(notificationID, mBuilder.build());
            }
    

    Hop this will help you.Thanks...

提交回复
热议问题