Android Question Ignore battery optimisations activity recall code required

Dear elite B4A programmers,
Please, could somebody recode this short Java code to B4A by using Java object of B4A? Aim of this short Java code which I Am sending short Java code here. Code allow B4A programmer to recall Ignore battery optimisations dialog. Dialog allow user to confirm, if he or she want to add his app to The ignore battery optimisations whitelist.
Code do not require to go through whole app list to set The ignore battery optimisations dialog. Do you think, that this Java code is also compatible with Android 12 or 10? Or it will only work for Android 9 and not for newer versions?

String packageName = getPackageName();
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
Intent whitelist = new Intent();
whitelist.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
whitelist.setData(Uri.parse("package:" + packageName));
whitelist.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

try {
startActivity(whitelist);
} catch (ActivityNotFoundException e) {
Logger.logStackTraceWithMessage(LOG_TAG, "Failed to call ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS", e);
 
Top