Android 确切时间通知
Android Notification on exact time
AlarmManager 的 setExact() 方法是否有替代方法?我想在确切的时间显示通知,但我不想将我的 minSdkVersion 提升到 19。现在我正在使用 AlarmManager 的 set() 方法,但是在未来很远的时间安排的警报不会在确切的时间通知用户(但 cca 10分钟后)。现在我使用的是 minSdkVersion 16 和 targetSdkVersion 21。我在 Android Developers 上发现了一条说明:
Note: Beginning in API 19, the trigger time passed to this method is treated as inexact: the alarm will not be delivered before this time, but may be deferred and delivered some time later. The OS will use this policy in order to "batch" alarms together across the entire system, minimizing the number of times the device needs to "wake up" and minimizing battery use. In general, alarms scheduled in the near future will not be deferred as long as alarms scheduled far in the future.
With the new batching policy, delivery ordering guarantees are not as strong as they were previously. If the application sets multiple alarms, it is possible that these alarms' actual delivery ordering may not match the order of their requested delivery times. If your application has strong ordering requirements there are other APIs that you can use to get the necessary behavior; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent).
Applications whose targetSdkVersion is before API 19 will continue to get the previous alarm behavior: all of their scheduled alarms will be treated as exact.
但使用 setExact() 或 setWindow() 对我来说不是解决方案。
谢谢回复。
查看当前API等级。
如果低于 19,则使用 set(),否则使用 setExact()。
要检查您的 OS 版本,请使用如下内容:
在您的导入部分:
import android.os.Build;
在您的声明中:
protected static final int Build_Version = Build.VERSION.SDK_INT;
然后就很容易查了
if(Build_Version < 19)
{
// Use set()...
}
else
{
// Use setExact()...
}
AlarmManager 的 setExact() 方法是否有替代方法?我想在确切的时间显示通知,但我不想将我的 minSdkVersion 提升到 19。现在我正在使用 AlarmManager 的 set() 方法,但是在未来很远的时间安排的警报不会在确切的时间通知用户(但 cca 10分钟后)。现在我使用的是 minSdkVersion 16 和 targetSdkVersion 21。我在 Android Developers 上发现了一条说明:
Note: Beginning in API 19, the trigger time passed to this method is treated as inexact: the alarm will not be delivered before this time, but may be deferred and delivered some time later. The OS will use this policy in order to "batch" alarms together across the entire system, minimizing the number of times the device needs to "wake up" and minimizing battery use. In general, alarms scheduled in the near future will not be deferred as long as alarms scheduled far in the future. With the new batching policy, delivery ordering guarantees are not as strong as they were previously. If the application sets multiple alarms, it is possible that these alarms' actual delivery ordering may not match the order of their requested delivery times. If your application has strong ordering requirements there are other APIs that you can use to get the necessary behavior; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent). Applications whose targetSdkVersion is before API 19 will continue to get the previous alarm behavior: all of their scheduled alarms will be treated as exact.
但使用 setExact() 或 setWindow() 对我来说不是解决方案。 谢谢回复。
查看当前API等级。
如果低于 19,则使用 set(),否则使用 setExact()。
要检查您的 OS 版本,请使用如下内容:
在您的导入部分:
import android.os.Build;
在您的声明中:
protected static final int Build_Version = Build.VERSION.SDK_INT;
然后就很容易查了
if(Build_Version < 19)
{
// Use set()...
}
else
{
// Use setExact()...
}