function GetPowerManager: JPowerManager;
var PowerServiceNative: JObject;
begin
PowerServiceNative := TAndroidHelper.Context.getSystemService(TJContext.JavaClass.POWER_SERVICE);
if not Assigned(PowerServiceNative)
then
raise Exception.Create('
Could not locate Power Service');
Result := TJPowerManager.Wrap((PowerServiceNative
as ILocalObject).GetObjectID);
if not Assigned(Result)
then
raise Exception.Create('
Could not access Power Manager');
end;
var WakeLock: JPowerManager_WakeLock =
nil;
function AcquireWakeLock(): Boolean;
var
PowerManager: JPowerManager;
begin
Result := Assigned(WakeLock);
if not Result
then
begin
PowerManager := GetPowerManager;
WakeLock := PowerManager.newWakeLock(TJPowerManager.JavaClass.SCREEN_BRIGHT_WAKE_LOCK,
StringToJString('
Delphi'));
Result := Assigned(WakeLock);
end;
if Result
then
begin
if not WakeLock.isHeld
then
begin
WakeLock.acquire;
Result := WakeLock.isHeld
end;
end;
end;
procedure ReleaseWakeLock;
begin
if Assigned(WakeLock)
then
begin
WakeLock.release;
WakeLock :=
nil
end;
end;