문제

How to get Name, Manufacturer and SerialNo of the build-in sensors of my Android device?

I have tried both methods that I found in the documentation and tutorials...

  TSensorManager.Current.Active := true;
  NumberofSensors := TSensorManager.Current.Count;
  MemoSensors.Lines.Clear;
  if NumberOfSensors = 0 then
    MemoSensors.Lines.Add('No Sensors Found')
  else
    for i := 0 to NumberOfSensors-1 do
    begin
      MemoSensors.Lines.Add( IntToStr(i) + '  Category:  ' + GetEnumName(System.TypeInfo(TSensorCategory), Ord(TSensorManager.Current.Sensors[i].Category)));
      if(TSensorManager.Current.Sensors[i].Category = TSensorCategory.Motion) then
      begin
        mSensorArray := TSensorManager.Current.GetSensorsByCategory(TSensorCategory.Motion);
        mMoSens := mSensorArray[0] as TCustomMotionSensor;
        if Assigned(mMoSens) then
        begin
            mMoSens.Start;
            MemoSensors.Lines.Add('      Name: ' + mMoSens.Name + ' Manufacturer: ' + mMoSens.Manufacturer + ' Model: ' + TSensorManager.Current.Sensors[i].Model + ' Serial Nr: '  + mMoSens.SerialNo);
            mMoSensorType :=  mMoSens.SensorType;
            MemoSensors.Lines.Add('      Type: ' + GetEnumName(System.TypeInfo(TMotionSensorType), Ord(mMoSens.SensorType))  + '  Category:  ' + GetEnumName(System.TypeInfo(TSensorCategory), Ord(mMoSens.Category)));
            mMoSens.Stop;
        end;
      end;
      //MemoSensors.Lines.Add(  '    Manufacturer: ' + TSensorManager.Current.Sensors[i].Manufacturer + ' Model: ' + TSensorManager.Current.Sensors[i].Model + ' Serial Nr: '  + TSensorManager.Current.Sensors[i].SerialNo);
    end;
  TSensorManager.Current.Active := false;

As you can see I try to read it from: mMoSens variable and straight form array Sensors[i]...

Both methods allow to read Category and Type of the sensor, but can't see Name, Vendor etc.... I also install software form GPlay and it read names and manufacturers of my device sensors.

도움이 되었습니까?

해결책 2

There's definition of procedure in the source code:

function TCustomSensor.GetSensorProperty(Prop: TProperty): string;
begin
  Result := '';
end;

... so there is no implementation for all sensor properties.

다른 팁

This feature is currently not supported by the FM platform on Android, as far as I can tell.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top