Reputation: 17
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());
}
Upvotes: 0
Views: 1156
Reputation: 2481
Use Uri.parse("android.resource://com.uks.uksnavigation/raw/notification")
.
Upvotes: 1