- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用显示通知。我想通过 addAction 向通知添加一个操作,导致通知消失并在一小时后重新出现,但是我不想为此打开一个 Activity ,最好的情况是:用户单击操作,通知消失并且然后在一小时后重新出现,就像通知的贪睡计时器一样。
有没有办法在不打开 Activity 的情况下做到这一点?
谢谢你的帮助
最佳答案
每个通知操作都来自 PendingIntent。当然,您不想启动 Activity ,也不必这样做。
您的案例的最佳选择是创建您的 PendingIntent:
public static PendingIntent getBroadcast (Context context, int requestCode, Intent intent, int flags)
这样,每当用户点击通知时,它就会在系统上生成一个广播。然后你必须创建一个 BroadcastReceiver , 以接收此广播并使用 AlarmManager 安排另一个 PendingIntent .第二个未决 Intent 将是一个不同的广播,无论何时触发,您的 BroadcastReceiver 都可以接收并显示新的通知。
有道理吗?
**编辑:
只是为了澄清成一个伪例子:
- Your app have a BroadcastReceiver registered in the Manifest to receive Broadcasts of 'com.yourapp.mybroadcast'
- Notification have a com.yourapp.mybroadcast PendingIntent with extras boolean isSchedule = true and int time = 60 (60 minutes)
- The user taps the notification and this broadcast is fired and your BroadcastReceiver receives
onReceive(Context context, Intent intent)
- Inside your onReceive you read isSchedule=true (meaning it have to create a new schedule and time = 60 minutes. So it uses the AlarmManager to create a new Broadcast PendingIntent with isSchedule = false; to be fired in 60 min
- The AlarmManager will call your BroadcastReceiver again in 60min but this time with isSchedule = false, so your BroadcastReceiver knows its time to show the notification again.
关于android - 向通知添加一个操作以再次显示通知,但稍后,就像通知的贪睡计时器一样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14937225/
我正在编写一个插件,有一个ajax调用向用户显示数据。 如果用户想在ajax成功时添加一些js?他可以从他的 js 脚本中做到这一点吗,比如定位这个 ajax 成功事件。 例如: $(documen
我有 html 代码,例如 - x 最初插入 div 'insert_calendar_eda_form'。 Javascript代码 calendar_eda_add
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 3 年前。 Improve this qu
我已经使用命令 sudo start myservice 启动了一个 upstart 服务。我想要一种方法,以便稍后我(或任何人)可以检查该服务是否已启动并正在运行。检查它的命令是什么? 最佳答案 找
我是一名优秀的程序员,十分优秀!