简体   繁体   English

Android Oreo中的通知

[英]Notifications in Android Oreo

First of all, I know this has been asked several times before, however I've yet to find a working solution so I thought about asking anyway. 首先,我知道这已经被问过几次了,但是我还没有找到一个可行的解决方案,所以我还是想问一下。

In my app I'm using a AlarmManager to trigger a notification at a specific moment. 在我的应用中,我正在使用AlarmManager在特定时刻触发通知。 It works all fine in Nougat and lower, however it never triggers when tested on Oreo (and suppose it wouldn't work on Pie either). 它在牛轧糖及更低的牛轧糖上都可以正常工作,但是在奥利奥(Oreo)上测试时永远不会触发(假设它在Pie上也不起作用)。

I've tried all sorts of things, like using setExactAndAllowWhileIdle . 我已经尝试过各种方法,例如使用setExactAndAllowWhileIdle Which according to other users should work on Oreo but it didn't work for me. 其他用户认为应该在Oreo上工作,但对我不起作用。 I also found about WorkManager, however people recommended not to use it in production apps since it's still in beta and apparently it's also not recommended if you need the task to run at a really specific time. 我还发现了有关WorkManager的信息,但是人们建议不要在生产应用程序中使用它,因为它仍处于测试阶段,并且如果您需要在特定时间运行任务,显然也建议不要使用它。

I would show my code however it's just a simple AlarmManager with a BroadcastReceiver like any other example you might find on the internet. 我将展示我的代码,但是它只是一个带有BroadcastReceiver的简单AlarmManager ,就像您在互联网上可能找到的任何其他示例一样。

This is a really app breaking "bug" for me and at this point I don't know what to do. 对我来说,这是一个真正的应用程序,可以打破“ bug”,目前我不知道该怎么办。 Thanks. 谢谢。

EDIT : The AlarmManager does work in Android Oreo and above, the problem was with the notifications. 编辑AlarmManager确实可以在Android Oreo及更高版本中使用,问题出在通知上。 Starting with Oreo you need to set up a NotificationChannel , otherwise the notifications are never going to show up. 从Oreo开始,您需要设置一个NotificationChannel ,否则通知将永远不会显示。 That's it. 而已。

Key point is that you have to use explicit broadcasts in case of Oreo. 关键是在奥利奥的情况下,您必须使用显式广播。

Discussion with solution . 讨论解决方案

Documentation . 文件资料

Try this, it may work. 试试这个,可能会起作用。 I was also facing same issue as yours and this code works fine for me. 我也遇到了与您相同的问题,此代码对我来说很好用。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(d.getTime(), pendingIntent), pendingIntent);
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    alarmManager.setExact(AlarmManager.RTC, d.getTime(), pendingIntent);
else
    alarmManager.set(AlarmManager.RTC, d.getTime(), pendingIntent);

setAlarmClock() method works in most of each and every conditions. setAlarmClock()方法适用于大多数情况。 Even if device is in Doze Mode , this method will work. 即使设备处于打ze模式 ,此方法也可以使用。

You can know more about setAlarmClock() method from here . 您可以从此处了解有关setAlarmClock()方法的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FCM通知无法在Android最新版本OREO中使用 - FCM notifications not working in Android latest version OREO 通知无法在Android Oreo(API 26)中显示 - Notifications fail to display in Android Oreo (API 26) Flutter 本地通知未在 Android Oreo 上显示图标 - Flutter local notifications not showing icon on Android Oreo android oreo上的通知 - 动态启用声音/振动 - Notifications on android oreo - dynamically enable sound/vibration Android Oreo 通知 - 检查是否启用了特定频道 - Android Oreo Notifications - check if specific channel enabled Android Oreo:通知通道的分组通知 - Android Oreo: Grouped Notifications With Notification Channels 在以下oreo的Android版本上无法接收通知 - Not able to receive notifications On Android version below oreo Urban Airship Android GCM 在 Android Oreo 和 Pie 上未收到推送通知 - Urban Airship Android GCM not receiving push notifications on Android Oreo and Pie 如何在 Android Oreo 的特定时间在 Android 上发出通知? - How To give notifications on Android on specific time in Android Oreo? Android Oreo设备未收到从AWS SNS发送的推送通知 - Android Oreo devices not receiving push notifications sent from AWS SNS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM