Question

I'm trying to make an alarm app, and I'm really close, but I want the alarm sound to keep playing until the user has manually disabled it via my app (puzzle to turn off alarm type idea). The problem Im having now is that the sound plays up until I pull down the notification drawer, then it stops. Here is the relevant code:

NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setSmallIcon(R.drawable.ic_launcher);
    notificationBuilder.setContentTitle(alarm.getLabel());
    notificationBuilder.setContentText(alarm.getMessage());
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    notificationBuilder.setSound(alarmSound);
    notificationBuilder.setOngoing(true);
    Notification notification = notificationBuilder.build();
    if(alarm.getVibrate()) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    }
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_INSISTENT;
    notificationManager.notify(2, notification);

I have tried messing around with the flags, but nothing seems to keep it playing... Thanks for any help in advance.

Was it helpful?

Solution

Found a solution. Had to use a background Service to play the ringtone rather than the notification manager.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top