java - 同时停止闹钟和闹钟铃声

标签 java android notifications broadcastreceiver alarm

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

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

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

    }

关于java - 同时停止闹钟和闹钟铃声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43262242/

相关文章:

java - 将 SQL 查询存储在简单的日志文件中

android - 包管理器 : List all app that can send notifications

android - 我希望在打开应用程序后关闭通知

ios - iOS本地通知唤醒应用程序

java - 是否有任何有效和优化的方法来在 long[] 数组中存储 500M+ 元素?

java - Java 中的 Curl --user 和 -d 等效项

java - 如何通过jdbc连接mysql

android - 动画师和动画有什么区别?

android - 在 Android M 中读取手机状态运行时错误

android - Flurry 在 android 中什么都不做