Android Question REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

Hackito

Member
hi, sorry for my bad english-google traductor :)

I understand that it is prohibited to use this permission in google play (REQUEST_IGNORE_BATTERY_OPTIMIZATIONS). There is another option? I'm making a radio app and I need it to keep ringing even with the cell phone on standby without the user having to manually modify the battery usage restriction. Thanks
 

PdeG

Member
Licensed User
Longtime User
Hi,

Perhaps tihs works,

Call it using
B4X:
IgnoreBatteryOptimizations




isIgnoringBatteryOptimizations():
#If JAVA
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.provider.Settings;
import android.net.Uri;
import anywheresoftware.b4a.BA;

public boolean isIgnoringBatteryOptimizations(){
Context context=this;
String packageName = context.getPackageName();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
return pm.isIgnoringBatteryOptimizations(packageName);
}

public void ShowPermissionDialog(){
    Intent intent = new Intent();
    Context context=this;
    String packageName = context.getPackageName();
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (pm.isIgnoringBatteryOptimizations(packageName)){
        BA.LogInfo("isIgnoringBatteryOptimizations TRUE");
        intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
    } else {
        BA.LogInfo("isIgnoringBatteryOptimizations FALSE");
        intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
        intent.setData(Uri.parse("package:" + packageName));
    }
    context.startActivity(intent);
}
#End If
 
Upvote 0
Top