同时停止闹钟和闹钟铃声

Stopping alarm and alarm ringtone together

我正在开发闹钟应用。 当它触发警报时,它会抛出带有禁用按钮的通知。 因此,当我单击禁用按钮时,它应该会停止闹钟铃声和闹钟。

因此,当我单击禁用按钮时,它会调用以下方法。 它停止警报。 但是我想知道这个铃声会在下一个约会的同一时间继续播放还是会永久删除闹钟?

public void dismissRingtone() {
    // stop the alarm rigntone
    Intent i = new Intent(this, RingtonePlayingService.class);
    stopService(i);

    // also dismiss the alarm to ring again or trigger again
    AlarmManager aManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    aManager.cancel(pendingIntent);

    // Canceling the current notification
    NotificationManager notificationManager =
            (NotificationManager)getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
    notificationManager.cancel(321);
}

试试吧,它会取消以后的闹钟。

    Intent intentAlarm = new Intent(this, AlarmReceiver.class);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // Set the alarm for a particular time.

    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);

    try {
        pendingIntent.cancel();
        alarmManager.cancel(pendingIntent);
    } catch (Exception e) {
        e.printStackTrace();

    }