0

Im using a Notifiation builder and want sound, vibration and light. vibration and light works fine but the sound doesnt wanna play. I tried many solutions here but most of em are for the deprecated version. in the code below u can see what im doing. i tried both alamsound and sound but none worked. do i need any permission ?

    public void createTestNotification(){
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    long[] vibrate = { 0, 100, 200, 300 };
    NotificationManager nm= (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    Uri sound = Uri.parse("android.resource://com.uks.uksnavigation/" + R.raw.notification);


    Intent intent = new Intent(this.getActivity(), MainActivity.class);
    intent.setAction("nachricht");
    PendingIntent pIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);

    Notification.Builder mBuilder =
            new Notification.Builder(getActivity())
    .setContentIntent(pIntent)
            .setSmallIcon(R.drawable.ic_stat_mail_aktiv)
            .setContentTitle("New Message")
            .setContentText("Nachrichten text text text")
            .setSound(sound)
            .setVibrate(vibrate)
            .setLights(Color.BLUE, 500, 500);

    nm.notify(1, mBuilder.build());     


}

1 Answer 1

1

Use Uri.parse("android.resource://com.uks.uksnavigation/raw/notification").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.