AlarmManager在安卓4.4.2停止工作(使用SetExact())

编程入门 行业动态 更新时间:2024-10-22 17:22:47
本文介绍了AlarmManager在安卓4.4.2停止工作(使用SetExact())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的code报警设定在特定时间熄灭。 报警机制的伟大工程的SDK< 19日,但19报警不会被触发。 这里是code,我设定闹钟:

I'm setting in my code an alarm to go off in specific time. The alarm mechanism works great on SDK < 19, but on 19 the alarms aren't fired. Here is the code where I set the alarm :

public void SetAlarm(Context context, Long executionTime) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReciever.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Only one alarm can live, so cancel previous. am.cancel(pi); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { am.set(AlarmManager.RTC_WAKEUP, executionTime, pi); } else { setAlarmFromKitkat(am, executionTime, pi); } }

由于我设置使用服务报警我用 GetApplicationContext()作为背景。

在的onReceive() code:

@Override public void onReceive(Context context, Intent intent) { for (SchedulerListener listener : listeners) { listener.fetchAndRebuildNotification(); } }

下面是声明的的BroadcastReceiver :

<receiver android:name="com.SagiL.myAppName.BroadCastReceivers.AlarmReciever" />

在回调中运行的服务的方法(这是还活着的时候报警应该火,发现它并没有启动一个)。

The callback runs a method in a service (which is still alive when the alarm supposed to fire, notice it doesn't starts one).

这整个事情是一个库这是用在我的应用程序,并有我宣布接收器以相同的方式。

This whole thing is a library which is used in my app, and there I declare the receiver the same way.

有时候报警做触发一次,但大多不火的。

Sometimes the alarm do fires once, but mostly it doesn't fire at all.

有没有人遇到过这样的事情吗? 我简直不敢相信这是常见的SDK 19日以来很多应用程序都使用 AlarmManager ,他们将打破太多,如果它是常见的。

Has anyone experienced such a thing ? I can't believe it's common to SDK 19 since a lot of apps are using AlarmManager and they will break too if it is common.

推荐答案

我有一个类似的问题,我的申请。我发现,使用 0 的作品 getBroadcast(...)的ID; 没有工作非常好,造成许多问题。

I had a similar problem with my application. I found out that using 0 ad the id in getBroadcast(...); didn't work very well and caused numerous problems.

试着改变 ID 从 0 报警的真实身份。

Try changing the id from 0 to the alarm's real id.

从:

PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

要:

PendingIntent pi = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);

更多推荐

AlarmManager在安卓4.4.2停止工作(使用SetExact())

本文发布于:2023-11-27 04:25:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   AlarmManager   SetExact

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!