AlarmManager在Lollipop中的Samsung设备上不起作用 [英] AlarmManager not working on Samsung devices in Lollipop

查看:119
本文介绍了AlarmManager在Lollipop中的Samsung设备上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个使用AlarmManager设置一堆警报(通常约50个)的应用,该警报需要在一年中的某个时间触发。
这是自4.4 kitkat更改AlarmManager以来我使用的代码。

I develop an app that uses AlarmManager to set a bunch alarms (usually around 50) that need to be fired at a certain time during the year. This is the code I'm using since 4.4 kitkat changed the AlarmManager.

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
long setDate = fireDate.getTime(); // it's a calendar date defined above
Intent intent = new Intent(LOCAL_DISPLAY_MESSAGE_ACTION);
PendingIntent pending = PendingIntent.getBroadcast(ctx,
                            id, intent, PendingIntent.FLAG_UPDATE_CURRENT);

if (Build.VERSION.RELEASE.startsWith("6")) {
    am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, setDate, pending);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
    am.setExact(AlarmManager.RTC_WAKEUP, setDate, pending);
} else {
    am.set(AlarmManager.RTC_WAKEUP, setDate, pending);
}

除了上面的代码,我使用的广播接收器在

Apart from the code above I'm using a broadcast receiver properly defined in the manifest.

public class LocalReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        PushWakeLocker.acquire(context);

        // do some stuff

        PushWakeLocker.release();
    }
}

更多信息可能有帮助。

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="19" />

自几个月前以来,我一直仅从三星设备获得过差评(5.0 /5.1 android版本),但根本不会收到本地通知。我的意思是,它没有发出警报,似乎设备跳过了它或没有唤醒。

Since a few months ago I've been getting bad reviews only from Samsung devices (5.0 /5.1 android version) that don't get their local notifications at all. I mean, it's not firing the alarm, it seems that the device skips it or does not wake up.

在测试中,主要使用的是带有5.0.1的三星S4。 ,我总是按时收到警报,所以这让我发疯。
仅供参考,该代码始终可以正常工作。

In the tests, mainly with a Samsung S4 with 5.0.1, I always get the alarms on time, so this is driving me crazy. FYI this code has always worked pretty fine.

我对此进行了大量研究,但不幸的是,我没有任何有用的信息。不是因为他们延迟收到了警报(正如我在某些主题中所读到的),而是因为他们根本没有得到警报。因此,这与棒棒糖和警报管理器中的已知问题无关。

I researched a lot about this but unfortunately I got no helpful information. It's not that they get the alarm with delay (as I've read in some threads), it's that they don't get it at all. So this is not about the known issue in lollipop and alarmmanager.

感谢您的宝贵时间,欢迎提出任何建议!

I appreciate your time and any suggestion is welcomed!

推荐答案

您的问题(或噩梦)是三星智能管理器。自2015年以来,此应用程序已预装在所有三星手机中,应该停用未使用的应用程序。
如何知道未使用哪些应用程序?您可能会问-简单:

Your problem (or nightmare) is the Samsung Smart Manager. This app comes pre-installed with all Samsung phones since 2015 and is supposed to deactivate Apps that are unused. "How does it know which apps are not used?" You may ask - simple:

每个用户三天未启动的应用都会被停用。

Every app that has not been launched by the user for 3 days gets deactivated.

所有剩余的AlarmManager条目-当然-也将被删除。您可以在他们的开发者论坛上阅读有关内容。随时关注此处此处,直到工作人员删除了这些线程。我还没有看到三星的人对此话题做出回应。

All remaining AlarmManager entries - of course - also get deleted. You can read about it on their "Developer Forums". Feel free to follow here or here until these threads get deleted by the staff. I have yet to see someone from Samsung respond to the topic.

修复此问题的唯一方法是通知应用程序用户有关情况并向他们显示如何在Smart Manager中将您的应用列入白名单。我们必须设置一个包含逐步说明的网站,逐步说明如何为我们的用户使用。

The only way to "fix" this is to inform the Users of your app about the situation and show them how to whitelist your app in Smart Manager. We've had to setup a website with step-by-step instructions showing how to do this for our users.

您可能会考虑设置后台服务,或者每六个小时左右调用一次AlarmManager-这些黑客都无法使用。

You may think about setting up a background service, or calling AlarmManager every six hours or so - none of these hacks will work.

这篇关于AlarmManager在Lollipop中的Samsung设备上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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