Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Desarrollo en Delphi para Android (https://www.clubdelphi.com/foros/forumdisplay.php?f=57)
-   -   Prevenir que Android entre en modo sleep (https://www.clubdelphi.com/foros/showthread.php?t=88859)

Fossy 14-08-2015 22:13:28

Prevenir que Android entre en modo sleep
 
Hola amigos:

Disculpad si esta pregunta ya está hecha, aunque he buscado y no he encontrado nada, pero tengo la necesidad de mantener la pantalla activa con mi App, y actualmente el problema que tengo es que Android apaga la pantalla de forma natural.

¿Cómo puedo prevenir esto?.

Gracias y saludos!.

AgustinOrtu 15-08-2015 01:05:19

Usando el Tasker

Fossy 15-08-2015 01:24:36

Cita:

Empezado por AgustinOrtu (Mensaje 495536)
Usando el Tasker

Ante todo gracias por tu respuesta.

No sé si me he explicado bien, pero no tiene nada que ver con usar apps de terceros, ni mucho menos instalar nada en el móvil.

Simplemente necesito dotar a mi App (Delphi XE7) para que la pantalla no se apague mientras la App esté en primer plano y activa. Es muy común usar esto en casi cualquier tipo de App, sobre todo las que graban vídeo y demás, donde es necesario estar constantemente mirando la pantalla.

He podido ver que hay que hacer uso de "Wake Lock", pero no he encontrado mucho mas.

Gracias.

Casimiro Notevi 15-08-2015 10:10:53

Me parece haber visto un ejemplo en Embarcadero. A ver si lo encuentro.

kurono 16-08-2015 05:25:02

hola fossy yo uso esta libreria para evitar apagar la pantalla en delphi xe5 no se si en xe7 funcionara pero aqui te lo dejo

Código Delphi [-]
unit Android.JNI.PowerManager;

interface

function AcquireWakeLock : Boolean;
procedure ReleaseWakeLock;

implementation

uses
  System.SysUtils,
  Androidapi.JNI,
  Androidapi.JNIBridge,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.JavaTypes,
  FMX.Helpers.Android;

type
  JPowerManager = interface;
  JWakeLock = interface;

  JWakeLockClass = interface(JObjectClass)
  ['{918E171F-CDB8-4464-9507-F49272CE7636}']
  end;

  [JavaSignature('android/os/PowerManager$WakeLock')]
  JWakeLock = interface(JObject)
  ['{D17B1136-FA15-4AEB-85B1-2D490F0FD320}']
    {Methods}
    procedure acquire; cdecl;
    procedure release; cdecl;
    function isHeld: Boolean; cdecl;
  end;
  TJWakeLock = class(TJavaGenericImport) end;

  JPowerManagerClass = interface(JObjectClass)
  ['{7D0696A2-ADEA-4158-AE1F-5E720DEDBCF9}']
    {Property methods}
    function _GetFULL_WAKE_LOCK: Integer; cdecl;
    function _GetSCREEN_BRIGHT_WAKE_LOCK: Integer; cdecl;
    function _GetSCREEN_DIM_WAKE_LOCK: Integer; cdecl;
    function _GetPARTIAL_WAKE_LOCK: Integer; cdecl;
    {Properties}
    //Keep screen on bright & keyboard on
    //Deprecated in API level 17 - Jelly Bean MR1
    property FULL_WAKE_LOCK: Integer read _GetFULL_WAKE_LOCK;
    //Keep screen on bright
    //Deprecated in API level 13 - Honeycomb MR2
    property SCREEN_BRIGHT_WAKE_LOCK: Integer read _GetSCREEN_BRIGHT_WAKE_LOCK;
    //Keep screen on dim
    //Deprecated in API level 17 - Jelly Bean MR1
    property SCREEN_DIM_WAKE_LOCK: Integer read _GetSCREEN_DIM_WAKE_LOCK;
    //Keep CPU running, screen & keyboard can go off
    property PARTIAL_WAKE_LOCK: Integer read _GetPARTIAL_WAKE_LOCK;
  end;

  [JavaSignature('android/os/PowerManager')]
  JPowerManager = interface(JObject)
  ['{DEAED658-4353-4D17-B0A3-8179E48BE87F}']
    {Methods}
    function newWakeLock(levelAndFlags: Integer; tag: JString): JWakeLock; cdecl;
  end;
  TJPowerManager = class(TJavaGenericImport) end;

function GetPowerManager: JPowerManager;
var
  PowerServiceNative: JObject;
begin
  PowerServiceNative := SharedActivityContext.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: JWakeLock = 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;
end.

Fossy 18-08-2015 09:50:46

Muchísimas gracias Kurono.

Tiene muy buena pinta!!. Lo pruebo esta noche y te digo :)

Gracias! ^\||/^\||/


La franja horaria es GMT +2. Ahora son las 01:43:43.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi