Work Manager Do Not Run When Proguarding App In Api 27,28,29
I have a periodic task that runs every 15 minutes. When proguarding the application. The work manager does not work if the app is killed from the background. Testing devices : One
Solution 1:
This happened due to battery optimization by various vendors this day. You need to disable the optimization and your work manager will work like a charm!!
private void checkBatteryOptimization(){
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (pm != null && !pm.isIgnoringBatteryOptimizations(getPackageName())) {
AlertBottomSheetFragment alertBottomSheetFragment = AlertBottomSheetFragment.newInstance();
alertBottomSheetFragment.setData("For Timely notifications please disable battery optimization for Your App", new AlertBottomSheetImpl() {
@Override
public void acceptAlertBottom() {
askIgnoreOptimization();
}
@Override
public void declineAlertBottom() {
}
});
alertBottomSheetFragment.show(getSupportFragmentManager(), FRAG_BOTTOM_SHEET_ALERT_TAG);
} else {
// already ignoring battery optimization code here next you want to do
Timber.i("already ignoring battery optimization code here next you want to do");
}
} else {
Timber.i("version below");
// already ignoring battery optimization code here next you want to do
}
}
private void askIgnoreOptimization() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, IGNORE_BATTERY_OPTIMIZATION_REQUEST);
}
}
Post a Comment for "Work Manager Do Not Run When Proguarding App In Api 27,28,29"