2

我正在尝试制作一个闹钟应用程序,我真的很接近,但我希望闹钟声音继续播放,直到用户通过我的应用程序手动禁用它(关闭闹钟类型想法的谜题)。我现在遇到的问题是声音一直播放,直到我拉下通知抽屉,然后它才停止。以下是相关代码:

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);

我试过弄乱旗帜,但似乎没有什么能让它继续播放......提前感谢您的帮助。

4

1 回答 1

-1

找到了解决方案。不得不使用后台服务来播放铃声而不是通知管理器。

于 2013-09-16T15:52:15.357 回答