DELPHI安卓定位权限申请

DELPHI安卓定位权限申请

安卓8及以后版本的权限分为静态和动态申请2部分,而之前的安卓版本只需要静态申请权限。

1)静态申请定位权限:

DELPHI安卓定位权限申请

2)动态申请定位权限:

uses
  System.Permissions,
{$IFDEF ANDROID}
  Androidapi.Jni.Os,
  Androidapi.Helpers,
{$ENDIF}
...
  FPermissionCoarseLocation: string;
  FPermissionFineLocation: string;
...
procedure TMainForm.FormCreate(Sender: TObject);
begin
{$IFDEF ANDROID}
  // Note we can alternatively use literal strings:
  //   ‘android.permission.ACCESS_COARSE_LOCATION‘
  //   ‘android.permission.ACCESS_FINE_LOCATION‘
  // according to the documentation:
  //   https://developer.android.com/reference/android/Manifest.permission#ACCESS_COARSE_LOCATION
  //   https://developer.android.com/reference/android/Manifest.permission#ACCESS_FINE_LOCATION
  FPermissionCoarseLocation := JStringToString(TJManifest_permission.JavaClass.ACCESS_COARSE_LOCATION);
  FPermissionFineLocation := JStringToString(TJManifest_permission.JavaClass.ACCESS_FINE_LOCATION);
{$ENDIF}
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
  PermissionsService.RequestPermissions([FPermissionCoarseLocation, FPermissionFineLocation], LocationPermissionRequestResult);
end; 

  3)运行效果图:

DELPHI安卓定位权限申请

DELPHI安卓定位权限申请

上一篇:Java实验四《Android程序设计》20155335俞昆


下一篇:移动APP测试8点注意事项