Jak uruchomić Light Sensor w Android'zie w Delphi XE5?

0

Witam, Chciałbym uruchomić Light Sensor w Androidzie ale nie mam pojecia jak to zrobic, próbowałem wyciągnąć dane z dołączonego do Delphi demo SensorInfo ale nie wychodzi mi to :(, czy któryś z Kolegów mógł by mi pomóc w tym?
"mój" kod wyglada tak:

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, system.sensors,
  FMX.Layouts, FMX.ListBox;

type
  TForm1 = class(TForm)
    Layout1: TLayout;
    Label1: TLabel;
    Layout2: TLayout;
    Button1: TButton;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    FShowInfo : Boolean ;
    FActiveSensor : TCustomSensor;
    LuxSensor : TCustomLightSensor;
    function GetInfoAboutLight(ASensor: TCustomSensor): string;
    function GetFullInfo(AAvailibleProperties: string): string;
    function ToFormStr(AProp : string; AVal : Single): string;


  public
    { Public declarations }

  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

const
  AllCat : TSensorCategories = [TSensorCategory.Light];
   tForm = '  %s =' + sLineBreak + '%30s        %3.5f ' + sLineBreak;


function TForm1.GetInfoAboutLight(ASensor: TCustomSensor): string;
var
  ls : TCustomLightSensor;
  LValues : string;
  LProp : TCustomLightSensor.TProperty;
begin
  LValues := '';
  ls := TCustomLightSensor(ASensor);
  for LProp in ls.AvailableProperties do
  begin
    case LProp of
      TCustomLightSensor.TProperty.Lux:
        LValues := LValues + ToFormStr('Lux',ls.Lux);
      //  label1.Text := LValues ;
   //   TCustomLightSensor.TProperty.Temperature:
   //     LValues := LValues + ToFormStr('Temperature', ls.Temperature);
   //   TCustomLightSensor.TProperty.Chromacity:
     //   LValues := LValues + ToFormStr('Chromacity', ls.Chromacity);
    end;
  end;
  Result := GetFullInfo(LValues) ;
end;

function TForm1.ToFormStr(AProp: string; AVal: Single): string;
begin
  Result := Format(tForm,[AProp,'', AVal]);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
Var
  ResultText : string;
  LStep : Single;
begin
   if Assigned(FActiveSensor) then
   begin
    case FActiveSensor.Category of
       TSensorCategory.Light: ResultText := GetInfoAboutLight(FActiveSensor);
     end;
     Label1.Text := ResultText;
    end;
end;

function TForm1.GetFullInfo(AAvailibleProperties: string): string;
begin
  Result :=  AAvailibleProperties;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  LSensorCat : TSensorCategory ;
begin
  TSensorManager.Current.Activate();
end;
end.

Nie mam pojecia jak wyciagnac informacje z sensora światła. Chociaż wydaje mi sie że powinienem aktywować ten sensor swiatla aby się do niego połączyć, tylko nie wiem jak :(.

dodanie znacznika <code class="delphi"> - furious programming

1

A tu podam rozwiązanie mojego problem jak by ktoś szukał, przypisane dla button1:

procedure TForm1.Button1Click(Sender: TObject);
var
  MySensorArray : TSensorArray;
  MyAmbientLightSensor : TCustomLightSensor;
begin
  try
    TSensorManager.Current.Activate; // activate sensor manager
    // use GetSensorsByCategory to see if a Light sensor is found
    MySensorArray := TSensorManager.Current.GetSensorsByCategory(TSensorCategory.Light);
    if MySensorArray <> nil then begin  // check if Ambient Light Sensor is found
      label1.text := 'Ambient Light Sensor Found';
      MyAmbientLightSensor := MySensorArray[0] as TCustomLightSensor;
      Label2.text := FloatToStr(MyAmbientLightSensor.Lux);  // display the Light sensor value
    end
    else begin
      label3.text := 'Ambient Light Sensor Not Found!'
    end;
  finally
    TSensorManager.Current.DeActivate // deactivate sensor manager
  end;
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1