【问题标题】:Using a broadcast receiver for alarm manager and notification使用广播接收器进行警报管理器和通知
【发布时间】:2013-04-16 06:51:00
【问题描述】:

我创建了一个闹钟应用,可以在闹钟响起时播放音乐。我也设置了一个通知。我正在使用广播接收器,但是当我离开创建它的活动并播放音乐时它就结束了。我的第一个问题是,广播接收器是否是处理此问题的最佳方法,并且在清单中实现接收器是消除丢失接收器问题的唯一方法。当我离开创建应用程序的活动时,我收到一个错误,因为我没有取消注册接收器。我的第一个应用程序,需要一些建议。如果需要,我可以提供代码。

【问题讨论】:

    标签: android notifications broadcastreceiver alarmmanager


    【解决方案1】:

    您可以使用内置警报通过挂起意图触发。这样你就不需要广播接收器了。

    【讨论】:

    • 你有使用内置闹钟的例子吗?我见过的大多数示例都使用广播接收器。
    • 这是一个触发午夜警报的示例。您可以根据需要设置时间。 Intent intentToFire = new Intent(); intentToFire.setClassName(packageName, className);日历时间 = Calendar.getInstance(); time.set(Calendar.HOUR_OF_DAY,0); time.set(Calendar.MINUTE,0); time.set(Calendar.AM_PM, Calendar.AM); alarmScheduleIntent = PendingIntent.getActivity(this, 0, intentToFire, PendingIntent.FLAG_UPDATE_CURRENT); alarmScheduleManager.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis, alarmScheduleIntent);
    • 感谢您的示例。这绝对有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多