AlarmManager在安卓4.4.2停止工作(使用SetExact()) [英] AlarmManager stops working in Android 4.4.2 (using SetExact())

查看:358
本文介绍了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())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆