小编use*_*060的帖子

如何在Doze模式下使用Android 6.0时使Alarm Manager工作?

我是Google Play上两个闹钟应用的开发者.我想让他们使用Android 6.0.但是,打盹模式使它们不响.我把它们放在白名单上,我放了一个前景通知图标,我不知道我还能做什么 - 当处于打盹模式时,警报管理器警报仍然被忽略.然而,时钟应用程序(这是一个Google Play而不是AOSP应用程序)是不同的.当在Clock应用程序上启用闹钟时,"adb deviceidle step"将始终显示为"active"且永远不会"idle","idle_pending"或其他任何内容.

Android在这里作弊,给自己的应用程序更多的力量,又名."拉苹果"?Google Play上的所有闹钟应用程序是否即将失效?有点担心,这些都是高质量的应用程序,每个人都需要一年的兼职开发时间,并且对我来说是很大的收入来源.关于如何让这些工作起作用的任何线索都将是一个巨大的帮助.

设置AlarmManager意图:

        Intent intent = new Intent(context, ReceiverAlarm.class);
        if (android.os.Build.VERSION.SDK_INT >= 16) {
            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        }
        amSender = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT); //FLAG_CANCEL_CURRENT seems to be required to prevent a bug where the intent doesn't fire after app reinstall in KitKat
        am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, scheduleToTime+1, amSender);
Run Code Online (Sandbox Code Playgroud)

和ReceiverAlarm类:

public class ReceiverAlarm extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    if (wakeLock == null) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); …
Run Code Online (Sandbox Code Playgroud)

android alarmmanager android-6.0-marshmallow

48
推荐指数
1
解决办法
2万
查看次数