How to set notification with custom sound in android

前端 未结 6 1890

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:17

    You should replace this line:

    notification.sound = Uri.parse("android.resource://com.example.serviceproject/" + R.raw.kalimba);
    

    with this:

    notification.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/raw/kalimba"));
    

    or in some cases:

    notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/raw/kalimba");
    

提交回复
热议问题