我有一个相对简单的设置,该设置应在一天中的特定时间触发警报并向用户显示通知.这是相对代码,
I have relatively simple setup that should trigger an alarm at certain time of the day and show a notification to user. here is relative code,
设置闹钟
long inTime = /*expirationTime*/ Calendar.getInstance().getTimeInMillis() + 10000; Intent startIntent = new Intent("parking.event"); startIntent.setClass(getBaseContext(), ParkingExpirationWarmingBroadcast.class); PendingIntent startPendingIntent = PendingIntent.getBroadcast(this, 99, startIntent, 0); alarmMgr.setExact(AlarmManager.RTC_WAKEUP, inTime, startPendingIntent);广播接收器已注册
<receiver android:name=".modules.parking.ParkingExpirationWarmingBroadcast" android:enabled="true"> <intent-filter> <action android:name="parking.event" /> </intent-filter> </receiver>广播接收器
class ParkingExpirationWarmingBroadcast : BroadcastReceiver() { @SuppressLint("NewApi") override fun onReceive(context: Context, intent: Intent) { } }仅当应用程序在后台运行时,接收器才会被触发.从多任务中轻扫应用程序后,通知将被清除,并且不会触发新的警报.我在Android 7.0上检查了此设置,无论是否运行应用程序,都会触发BroadcastReceiver.
The receiver is only getting triggered if app is in background. as soon as i swipe the app from multitasking, the notification is cleared and no new Alarms are triggered. I checked this setup on Android 7.0 and BroadcastReceiver is triggered regardless of app running or not.
我知道有关Android Oreo中隐式广播的限制,但是我不认为我上面提到的意图被认为是隐式的.
I am aware regarding restrictions over implicit broadcasts in Android Oreo but i don't believe the intent that i have mentioned above is considered implicit.
谁能指出我做错了什么?
Can anyone point out what i am doing wrong?
推荐答案强制关闭应用会破坏其组件.这就是强制停止的作用.这不是错误,它是一个很大的功能.遵循以下主题,android框架工程师已对其进行了讨论. groups.google/forum/? fromgroups =#!topic/android-developers/anUoem0qrxU
Force closing an app destroys its components . This is what force stop does. It's not a bug, it is very much a feature. Follow the following thread , it has been discussed by android framework engineers . groups.google/forum/?fromgroups=#!topic/android-developers/anUoem0qrxU
更多推荐
奥利奥:未运行应用程序时未触发警报
发布评论