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.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
uses
AndroidAPI.JNI.GraphicsContentViewText,
AndroidAPI.JNI.JavaTypes,
AndroidAPI.Helpers,
FMX.Helpers.Android;
function BatteryPercent(const aContext: JContext): Integer;
var
filter: JIntentFilter;
battery: JIntent;
level, scale: Integer;
begin
filter := TJIntentFilter.Create;
filter.addAction(TJIntent.JavaClass.ACTION_BATTERY_CHANGED);
battery := aContext.registerReceiver(NIL, filter);
level := battery.getIntExtra(StringToJString('level'), -1);
scale := battery.getIntExtra(StringToJString('scale'), -1);
result := (100 * level) div scale;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(BatteryPercent(SharedActivityContext)));
end;
end.
XE6 安卓电量检测
最新推荐文章于 2024-05-30 15:25:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)