【Delphi】Android 动态改变屏幕亮度

有时,我们看到别人做的Android程序在出示二维码让别人扫描的时候,屏幕会高亮(亮度变满),扫描完成后下一个界面又恢复正常亮度。这个如何实现呢?

 

【Delphi】Android 动态改变屏幕亮度_第1张图片

亮度值:0-1 浮点。 1最亮,0黑暗。  Android 32位正常,但是Android 64位无效,原因未知,如果你有解决办法,请留言!

代码如下:

unit uForm_Screen;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts, FMX.Memo.Types,

  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.Helpers,

  FMX.ScrollBox, FMX.Memo;

type
  TForm1 = class(TForm)
    Layout1: TLayout;
    Button_FULL: TButton;
    Button_NONE: TButton;
    Memo1: TMemo;
    procedure Button_FULLClick(Sender: TObject);
    procedure Button_NONEClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.Button_FULLClick(Sender: TObject);
var
 jp     : JWindowManager_LayoutParams;
 NatWin : JWindow;
begin
  //改变屏幕亮度
  NatWin := TAndroidHelper.Activity.getWindow;
  NatWin.addFlags(TJWindowManager_LayoutParams.javaclass.FLAG_KEEP_SCREEN_ON);


  jp := NatWin.getAttributes;
  jp.screenBrightness := TJWindowManager_LayoutParams.JavaClass.BRIGHTNESS_OVERRIDE_FULL;

  TAndroidHelper.Activity.getWindow.setAttributes(jp);


  {$IFDEF ANDROID64}
    Memo1.Lines.Add('全亮: ' + 'ANDROID64');
  {$ELSE}
    Memo1.Lines.Add('全亮: ' + 'ANDROID32');
  {$ENDIF}


end;

procedure TForm1.Button_NONEClick(Sender: TObject);
var
 jp     : JWindowManager_LayoutParams;
 NatWin : JWindow;
begin
  //改变屏幕亮度
  NatWin := TAndroidHelper.Activity.getWindow;
  NatWin.addFlags(TJWindowManager_LayoutParams.javaclass.FLAG_KEEP_SCREEN_ON);


  jp := NatWin.getAttributes;
  jp.screenBrightness := TJWindowManager_LayoutParams.JavaClass.BRIGHTNESS_OVERRIDE_NONE;

  TAndroidHelper.Activity.getWindow.setAttributes(jp);

  {$IFDEF ANDROID64}
    Memo1.Lines.Add('正常: ' + 'ANDROID64');
  {$ELSE}
    Memo1.Lines.Add('正常: ' + 'ANDROID32');
  {$ENDIF}

end;

end.

你可能感兴趣的:(Android,Delphi,delphi,android,屏幕亮度,screen)