Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-other / 2020-08

please how to transform The following short java code to Pascal?

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mgr. Janusz Chmiel

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.

Reply by email