【问题标题】:Cancel alarm with notification android when app is closed应用关闭时通过通知android取消警报
【发布时间】:2018-04-17 02:31:15
【问题描述】:

我已经在我的应用程序中实现了一个提醒系统,它使用 android 提供的AlarmManager。一旦警报启动(当应用程序打开或关闭时),我已经初始化了要触发的通知,但我似乎无法在任何一种状态下关闭警报。

我似乎无法在任何地方找到我的答案。这可能吗?

【问题讨论】:

  • 你能显示你当前关闭闹钟的代码吗?

标签: java android notifications broadcastreceiver alarmmanager


【解决方案1】:
AlarmManager alarmManager = (AlarmManager) 
getSystemService(Context.ALARM_SERVICE);

Intent myIntent = new Intent(getApplicationContext(), YourService.class);

PendingIntent pendingIntent = 
PendingIntent.getBroadcast(getApplicationContext(), 1, myIntent,                                

PendingIntent.FLAG_UPDATE_CURRENT);

alarmManager.cancel(pendingIntent);

【讨论】:

  • “Contect.ALARM_SERVICE”中的上下文是否需要与创建警报的上下文相同,或者用户点击通知时也会在屏幕上创建警报?
  • 您是否在您的服务类中实现了 onDestroy()?尝试这样做,否则发布您的代码以查看它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多