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, FMX.Layouts, FMX.ListBox,
Androidapi.Helpers, Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.JavaTypes
;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private 宣言 }
public
{ public 宣言 }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
var
ifl: JIntentFilter;
ctx: JContext;
bStatus: JIntent;
level, scale: Integer;
begin
ifl := TJintentFilter.JavaClass.init(TJIntent.JavaClass.ACTION_BATTERY_CHANGED);
ctx := TAndroidHelper.Context;
bStatus := ctx.registerReceiver(nil, ifl);
//BatteryManager.EXTRA_LEVEL字符串//现实该水平 // BatteryManager.EXTRA_SCALE的现实串标度
level := bStatus.getIntExtra(StringToJString('level'), -1);
scale := bStatus.getIntExtra(StringToJstring('scale'), -1);
ListBox1.Items.Add('Battery');
ListBox1.Items.Add(IntToStr((100*level) div scale));
end;
end.