下面的程序,可以实现Android下获取GNSS的NMEA0183数据:

unit utAndroidNmea;interfaceuses Androidapi.JNIBridge, Androidapi.JNI.App, Androidapi.NativeActivity, Androidapi.JNI.JavaTypes, Androidapi.JNI.Location;type  TonNmeaReceived=procedure(timestamp: Int64; nmea: String) of Object;  TJGpsStatus_NmeaListener = class(TJavaGenericImport<JGpsStatus_NmeaListenerClass, JGpsStatus_NmeaListener>) end;  TNmeaProvider=class(TJavaLocal,JGpsStatus_NmeaListenerClass, JGpsStatus_NmeaListener)  protected    FLocationManager:JLocationManager;    FOnNmeaReceived:TonNmeaReceived;  public    procedure onNmeaReceived(timestamp: Int64; nmea: JString); cdecl;  public    constructor Create;    destructor Destroy;override;    function Run:Boolean;    property OnNmeaLineReceived:TOnNmeaReceived read FOnNmeaReceived write FOnNmeaReceived;  end;implementationuses Androidapi.Helpers, Androidapi.JNI.GraphicsContentViewText,  FMX.Helpers.Android,FMX.Platform.Android, System.SysUtils, System.Android.Sensors;{ TNmea }constructor TNmeaProvider.Create;begin  inherited Create;end;destructor TNmeaProvider.Destroy;begin  if Assigned(FLocationManager) then FLocationManager.removeNmeaListener(Self );  inherited;end;procedure TNmeaProvider.onNmeaReceived(timestamp: Int64; nmea: JString); cdecl;begin  if Assigned(FOnNmeaReceived) then FOnNmeaReceived(timestamp, JStringToString(nmea));end;function TNmeaProvider.Run:Boolean;begin  CallInUiThread(procedure  var    LocationService: JObject;  begin    LocationService := SharedActivityContext.getSystemService(TJContext.JavaClass.LOCATION_SERVICE);    FLocationManager := TJLocationManager.Wrap((LocationService as ILocalObject).GetObjectID);    FLocationManager.addNmeaListener(Self);  end);end;end.

用法:

在Form中添加一个TLocationSensor, 设置Active:=True;

然后定义OnNmeaReceive方法:

procedure TForm1.OnNmeaReceived(timestamp: int64; nmeasentence: String);begin  FStream.Write(PChar(nmeasentence)^, Length(nmeasentence)*sizeof(Char));end;

更多相关文章

  1. android中的自定义控件
  2. android定义可以被其他程序调用的activity
  3. 自定义控件其实很简单2/3
  4. Android自定义标题栏
  5. TextView英文自动换行解决方法
  6. Android 利用animation-list自定义progressbar动画出现图片平铺
  7. [置顶] Android按返回键退出程序但不销毁

随机推荐

  1. Android:res之selector背景选择器
  2. Android(安卓)Tutorial(3)Android(安卓)M
  3. Gradle sync failed: Could not GET 'htt
  4. android 加载图片到gallery
  5. 可点击价格走势图-贝塞尔曲线
  6. android布局属性详解
  7. android预定义样式简述
  8. Cordova 3.x 源码分析(6) -- cordova.js本
  9. Android(安卓)Home's favorite.xml
  10. Android学习知识点之相对布局