delphi - Dim Screen Android Firemonkey -


does know how dim screen on delphi firemonkey android? i've been googling around , searching find how remove auto dim android acquiring wakelock (delphi xe5 android. how use powermanager.wakelock?).

at best i'd achieve 2 states: evening = 20% brightness daytime = 100% brightness

i using delphi 10.1 berlin. thank help.

taking this stack overflow question, has java solution, guide rustled helper unit should work in delphi versions around xe8 10.1 berlin, seems trick:

unit screenbrightnessu;  interface  function getscreenbrightness: byte; procedure setscreenbrightness(brightness: byte);  implementation  uses   miscu,   fmx.helpers.android, {$if rtlversion >= 31}   fmx.dialogservice, {$else}   fmx.dialogs, {$endif}   system.uitypes,   system.sysutils,   androidapi.helpers,   androidapi.jni.app,   androidapi.jni.provider,   androidapi.jni.graphicscontentviewtext;  function getscreenbrightness: byte; var   resolver: jcontentresolver; begin   resolver := {$if rtlversion >= 30}     tandroidhelper.contentresolver; {$else}     sharedactivitycontext.getcontentresolver; {$endif}   result := tjsettings_system.javaclass.getint(     resolver,     tjsettings_system.javaclass.screen_brightness); end;  procedure setscreenbrightness(brightness: byte); var   resolver: jcontentresolver;   attainedbrightness: single;   layoutparams: jwindowmanager_layoutparams;   window: jwindow; begin   if not haspermission('android.permission.write_settings') {$if rtlversion >= 31}     tdialogservice.messagedialog('app not have write_settings permission', tmsgdlgtype.mterror, [tmsgdlgbtn.mbcancel], tmsgdlgbtn.mbcancel, 0, nil) {$else}     messagedlg('app not have write_settings permission', tmsgdlgtype.mterror, [tmsgdlgbtn.mbcancel], 0) {$endif}   else   begin {$if rtlversion >= 30}     resolver := tandroidhelper.contentresolver; {$else}     resolver := sharedactivitycontext.getcontentresolver; {$endif}     // set manual mode (set automatic mode off)     tjsettings_system.javaclass.putint(       resolver,       tjsettings_system.javaclass.screen_brightness_mode,       tjsettings_system.javaclass.screen_brightness_mode_manual);     // set required brightness     tjsettings_system.javaclass.putint(       resolver,       tjsettings_system.javaclass.screen_brightness,       brightness);     try       attainedbrightness := getscreenbrightness;       callinuithread(         procedure         begin   {$if rtlversion >= 30}           window := tandroidhelper.activity.getwindow;   {$else}           window := sharedactivity.getwindow;   {$endif}           layoutparams := window.getattributes;           layoutparams.screenbrightness := attainedbrightness / 255;           window.setattributes(layoutparams);         end);     except       // onoes!!!!       // <sweeps issue under carpet>     end;   end; end;  end. 

you'll note code permission checking via helper unit below. not vital long ensure have write_settings permission set in project android build configurations.

unit miscu;  interface  function haspermission(const permission: string): boolean;  implementation  uses   fmx.helpers.android,   androidapi.helpers,   androidapi.jni.javatypes,   androidapi.jni.graphicscontentviewtext;  function haspermission(const permission: string): boolean; begin   //permissions listed @ http://d.android.com/reference/android/manifest.permission.html {$if rtlversion >= 30}   result := tandroidhelper.context.checkcallingorselfpermission( {$else}   result := sharedactivitycontext.checkcallingorselfpermission( {$endif}     stringtojstring(permission)) =     tjpackagemanager.javaclass.permission_granted end;  end. 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -