[fpc-other] please how to transform The following short java code to Pascal?

Mgr. Janusz Chmiel janusz.chmiel at volny.cz
Wed Aug 5 10:39:51 CEST 2020


Dear experiences developers here,
	Please who of us would give Me a piece of advice, how to transform
The following Java code to Pascal?
The aim is to recall simple ignore battery optimisations confirmation
dialog. This dialog contain only two buttons, OK or storno.
It is not necessary to go through The whole complex ignore battery
optimisations dialog, select all apps and finding some Pascal app nd giving
it The permission to ignore battery optimisations. The code become from
Termux Java code.

                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) {

Is it technically possible to recode The code so it will be compatible with
PCJVM and will it work on Android?
Sure. It is possible to recall complex ignore battery optimisations dialog.
But I would like to recall its simple form.
The following other code recall complex form of this dialog. It work too.
In The public decleration source code area. Add

pm: AOPowerManager;
in other source code part add

pm:= AOPowerManager(getSystemService(ACContext.POWER_SERVICE)) ;
if (AOBuild.InnerVERSION.fSDK_INT >= AOBuild.InnerVERSION_CODES.M) then
begin
if (not pm.isIgnoringBatteryOptimizations(getPackageName())) then begin
// Prompt the user to disable battery optimization
intent := ACIntent.create;
intent.setAction(APSettings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
startActivity(intent);
end;
end;
Thank you very much for yours help and advices.



More information about the fpc-other mailing list