Android实例-屏幕操持常亮(XE8+小米2)
相关资料:
http://www.bubuko.com/infodetail-163304.html
结果:
1.打开权限Wake lock为True。
第三方单元:
unit Android.JNI.PowerManager; interface function AcquireWakeLock : Boolean;
procedure ReleaseWakeLock; implementation uses
System.SysUtils,
Androidapi.Helpers,
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<JWakeLockClass, JWakeLock>) 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<JPowerManagerClass, JPowerManager>) 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('Runing'));
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.
实例代码:
unit Unit1; 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; type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation
uses
Android.JNI.PowerManager;//需要引入
{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} procedure TForm1.Button1Click(Sender: TObject);
begin
AcquireWakeLock;//获取唤醒锁
end; procedure TForm1.Button2Click(Sender: TObject);
begin
ReleaseWakeLock;//释放唤醒锁
end; end.
Android实例-屏幕操持常亮(XE8+小米2)的更多相关文章
- android的屏幕保持常亮
1.Wake Lock是一种锁的机制 在Manifest.xml文件里面用user-permission声明.代码如下: 这种方法,在安装apk时,系统会提示安装人是否允许使用禁止休眠功能. < ...
- 关于android的屏幕保持常亮
实现这一功能的方法有两种,一种是在Manifest.xml文件里面声明,一种是在代码里面修改LayoutParams的标志位.具体如下: 1.在Manifest.xml文件里面用user-permis ...
- [转]delphi xe6 android屏幕操持常亮
1) setting the Project Options, Uses Permissions, Wake lock = True 2) Adding Android.JNI.PowerManage ...
- Android实例-利用WebBrowser实现浏览器(XE8+小米2)
结果: 1.网络好的情况下,打开很快,很流畅. 2.地址栏真心不好使,如果真要做应用,这块必须自己优化一下. 实例代码: unit Unit1; interface uses System.SysUt ...
- Android实例-TRectangle加载图片(XE8+小米2)
结果: 1.加载图片很流畅,可以做背景用. 2.现在是加载了正形与圆形,其他形状能不能加载呢?自己测试哦,要多动手才行. 3.需要把图片打到包里哦(路径为“assets\internal\”). 实例 ...
- Android实例-使用自定义字体文件(XE8+小米2)
结果: 1.需要修改DELPHI自身的FMX.FontGlyphs.Android.pas,复制到程序的根目录下(红色部分为修改过的). 2.字体文件从 C:\Windows\Fonts 直接拷贝到A ...
- Android实例-多窗口的切换(XE8+小米2)
1.图片一是程序运行后的界面. 2.图片二是点击"非模态显示"的界面. 3.图片三是点击"模诚显示"的界面(提示平台不支持). unit Unit1; inte ...
- Android实例-全屏显示程序(XE10+小米2)(无图)
方法一:选中窗体->BorderStyle改为“None” 方法二: 1.下载第三方控件QAndroid.Shell 2.执行FShell.Execute('su -c mount -o rem ...
- Xamarin Essentials教程屏幕常亮ScreenLock
Xamarin Essentials教程屏幕常亮ScreenLock 在一段时间内,如果用户没有对设备进行操作,设备就会自动关闭屏幕.用户必须手动操作,才能点亮屏幕.但是很多应用需要在用户没有操作 ...
随机推荐
- 内核MKDEV(MAJOR, MINOR)宏
版本:linux-2.6.24.4宏: MKDEV(MAJOR, MINOR); 说明: 获取设备在设备表中的位置. MAJOR 主设备号 MINOR 次设 ...
- HDU 4906 状态压缩dp
Our happy ending Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- Smack IQ包的扩展
前几天一直很烦躁,怎么扩展smack的IQ包堵了我好久,今天静下心来看了下smack的源码,把这个问题解决了.下面给出步骤: 如果我们要扩展一个如下所示的IQ包: <iq id="00 ...
- uva10375 Choose and divide
唯一分解定理. 挨个记录下每个质数的指数. #include<cstdio> #include<algorithm> #include<cstring> #incl ...
- UVa 10870 (矩阵快速幂) Recurrences
给出一个d阶线性递推关系,求f(n) mod m的值. , 求出An-dv0,该向量的最后一个元素就是所求. #include <iostream> #include <cstdio ...
- I.MX6 android 获取framebuffer信息
/******************************************************************************** * I.MX6 android 获取 ...
- 函数与关系实例,函数运算与SQL,试验与关系元组
函数是一个集合,它的每个元素都是二元组或多元组.例如 f = { (x, y) | x∈R & y∈R & y = 2x } ,g = { (x, y, z) | (x, y, z)∈ ...
- delphi 编译的时候 把Warning去除的方法
delphi 编译的时候 把Warning去除的方法 在 添加 {$WARNINGS OFF}
- js除法余数
return (Math.round(rs*100)/100); //保保留小数点后两位数: //如果要保留三位则改为:Math.round(rs*1000)/1000; //如果要保留四位则改为:M ...
- C#中的值类型(value type)与引用类型(reference type)的区别
ylbtech- .NET-Basic:C#中的值类型与引用类型的区别 C#中的值类型(value type)与引用类型(reference type)的区别 1.A,相关概念返回顶部 C#中 ...