AlarmManager在使用Android Lollipop 5.0.2的三星设备上不起作用 [英] AlarmManager doesn't work on samsung device with Android lollipop 5.0.2

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

问题描述

我的AlarmManager API出现问题,它根本无法在三星设备上启动,但可以在其他Android设备上运行...

I have an issue with the AlarmManager API, it doesn't fire at all on my samsung device, but it works on other Android device...

我的代码是这样的:

 public void setAlarm(int hourAlarm,  int minutesAlarm, int numeroAlarm, boolean yesOrNoRepeatAlarm) {


    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, numeroAlarm, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Log.i("numeroAlarm", numeroAlarm + "");
    Calendar calendar = Calendar.getInstance();

    if( (calendar.get(Calendar.HOUR_OF_DAY) > hourAlarm) ||
            ( calendar.get(Calendar.HOUR_OF_DAY) == hourAlarm && calendar.get(Calendar.MINUTE) > minutesAlarm)) {

        calendar.add(Calendar.DATE, 1);
    }

    calendar.set(Calendar.HOUR_OF_DAY, hourAlarm);
    calendar.set(Calendar.MINUTE, minutesAlarm);

    Log.i("timeInMillis", calendar.getTimeInMillis() + "");
    Log.i("repeatingAlarm", yesOrNoRepeatAlarm + "");

    if(yesOrNoRepeatAlarm) {

        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
    }
    else {

        alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    }

}

它可以在其他设备上完美运行(特别是在kitkat上),但不在我的三星设备上的lolipop上,
请问您有什么想法吗?

It works perfectly on other device (specially on kitkat) but not on lolipop in my samsung device, do you have any idea please ?

推荐答案

I遇到相同的问题,经过大量搜索和解决方法后,我发现问题可能出在 Lollipop 及更高版本中的Samsung设备的Smart Manager。如果手机用电池供电且屏幕关闭,则此组件可能会延迟警报管理器关闭,并在3分钟后触发。当然,您可以在

I had the same problem and after a lot of searching and workaround, I figured that Smart Manager of Samsung Devices in Lollipop and above may be the problem. This component can delay the Alarm Manager to goes off, it is triggered after 3 minutes, if the mobile is working on battery and with the screen closed. Of course you can deactivate the Smart Manager look at this :


  • 在设备上启动Samsung Smart Manager应用程序

  • 点击电池

  • 点击应用程序优化

  • 详细信息

  • 查找您的APP

  • 选择已禁用

  • Launch Samsung Smart Manager application on the device
  • Tap Battery
  • Tap App optimization
  • Detail
  • Find Your APP
  • Select "Disabled for"

但是在我的情况下,它不起作用,都没有禁用Smart Manager并在两台使用 Lollipop 的三星设备中工作。它的工作是通过重构应用程序包的名称以包含 String alert或 alarm(例如<$ c $)来愚弄 Smart Manager。 c> com.example.alarm.myApplication 。您还可以参考此链接以了解更多信息。

But in my case it didn't work, neither disabling the Smart Manager worked in 2 Samsung devices with Lollipop . What it did work was to "fool" Smart Manager by refactoring the name of my application's package to contains the String "alert" or "alarm", for example com.example.alarm.myApplication. You can also refer to this link for more information.

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

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