AlarmManager在使用Android Lollipop 5.0.2的三星设备上不起作用

编程入门 行业动态 更新时间:2024-10-20 09:23:18
本文介绍了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(例如 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的三星设备上不起作用

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

发布评论

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

>www.elefans.com

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