修复 XE8 for Android 方向传感器 headingX,Y,Z 不会动的问题

问题:XE8 for Android 方向传感器无法正常运作(在 XE7 是正常的)

测试:官方示例 Samples\Object Pascal\Mobile Snippets\OrientationSensor\

适用:XE8 for Android

修复方法:

请将源码 System.Android.Sensors.pas 复制到自己的工程目录里,再进行修改。

修改下面代码:

  TAndroidNativeMagneticSensor = class(TCustomOrientationSensor)
  strict private
    FNativeSensor: TNativeSensor;
  protected
    function GetUpdateInterval: Double;  override;
    procedure SetUpdateInterval(AInterval: Double); override;
    function GetOrientationSensorType: TOrientationSensorType; override;
{+++>} // 加入下面二行代码
    function DoStart: Boolean; override;
    procedure DoStop; override;
{<+++}
    function GetSensorCategory: TSensorCategory; override;
    function GetState: TSensorState; override;
    function GetTimeStamp: TDateTime; override;
    function GetAvailableProperties: TCustomOrientationSensor.TProperties; override;
    function GetDoubleProperty(Prop: TCustomOrientationSensor.TProperty): Double; override;
  public
    constructor Create(AManager: TSensorManager); override;
    function Supported: Boolean;
  end;

找到 TAndroidNativeMagneticSensor.Create 加入下面代码:

... 略 ...

constructor TAndroidNativeMagneticSensor.Create(AManager: TSensorManager);
begin
  inherited;
  FNativeSensor := TNativeSensor.Create(ASENSOR_TYPE_MAGNETIC_FIELD);
end;

{+++>} // 加入下面代码
function TAndroidNativeMagneticSensor.DoStart: Boolean;
begin
  Result := FNativeSensor.DoStart;
end;

procedure TAndroidNativeMagneticSensor.DoStop;
begin
  inherited;
  FNativeSensor.DoStop;
end;
{<+++} // 加入上面代码 

... 略 ...

 

posted @ 2015-05-12 14:43  龟山Aone  阅读(1202)  评论(0编辑  收藏  举报