我正在尝试使用Embarcadero XE5并在Android 4.2.2上运行Galaxy S4的环境传感器。 这是我正在使用的代码,但是我收到了访问冲突。 你能帮帮我吗?
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Sensors,
FMX.StdCtrls, FMX.Edit, System.TypInfo;
type
TForm1 = class(TForm)
btn1: TSpeedButton;
lbl1: TLabel;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.btn1Click(Sender: TObject);
var
LManager : TSensorManager;
LCustomEnvironmentalSensor : TCustomEnvironmentalSensor;
LSensor : TCustomSensor;
begin
LManager := TSensorManager.Current;
LManager.Activate;
LCustomEnvironmentalSensor:= LSensor as TCustomEnvironmentalSensor;
lbl1.Text := FloatToStr(LCustomEnvironmentalSensor.Temperature.);
end;
end.
答案 0 :(得分:0)
我知道TCustomEnvironmentalSensor只是应用程序代码中传感器实例的一个非初始化类...尝试名为SensorInfo的FireMonkey演示项目中的代码:)
LSensorArray := TSensorManager.Current.GetSensorsByCategory(ASensorCategory);
for LSensor in LSensorArray do
begin
// do some procedures on the LSensor
// from TCustomEnvironmentalSensor class :)
end