标签:play 版本 npe length string oca dev use tostring
安卓蓝牙动态权限
安卓7.0及以下版本
procedure TForm6.FormCreate(Sender: TObject); begin {$IFDEF ANDROID} FLocationPermission := JStringToString(TJManifest_permission.JavaClass.ACCESS_COARSE_LOCATION); {$ENDIF} end;
上述代码里面用到的 JStringToString 要 Uses Androidapi.Helpers;
上述代码中还有一个 DisplayRationale 也是一个函数:
procedure TForm6.DisplayRationale(Sender: TObject; const APermissions: TArray<string>; const APostRationaleProc: TProc); begin TDialogService.ShowMessage(‘We need to be given permission to discover BLE devices‘, procedure(const AResult: TModalResult) begin APostRationaleProc; end) end;
在 RequestPermissionsResult 这个函数里面,判断是否通过权限,如果通过,才去调用蓝牙的方法。
procedure TForm6.RequestPermissionsResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>); begin // 1 permissions involved: ACCESS_COARSE_LOCATION if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then StartBLEDiscovery else TDialogService.ShowMessage(‘Cannot start BLE scan as the permission has not been granted‘); end;
标签:play 版本 npe length string oca dev use tostring
原文地址:https://www.cnblogs.com/hnxxcxg/p/12114403.html