setExactAndAllowWhileIdle() for alarmmanager is not working properly

后端 未结 3 565
野性不改
野性不改 2020-12-28 20:50

I am developing an app which needs to perform particular action on the exact time which user has set. For this i am using setExactAndAllowWhileIdle() method bec

3条回答
  •  没有蜡笔的小新
    2020-12-28 21:07

    you can whitelist your app from doze mode by ignoring battery optimizations..

    Add permission

    
    

    request whitelist your app

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                Intent intent = new Intent();
                String packageName = getPackageName();
                PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
                if (!pm.isIgnoringBatteryOptimizations(packageName)) {
                    intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
                    intent.setData(Uri.parse("package:" + packageName));
                    startActivity(intent);
                }
            }
    

    Note: Neither setAndAllowWhileIdle() nor setExactAndAllowWhileIdle() can fire alarms more than once per 15 minutes per app.

提交回复
热议问题