DELPHI安卓定位权限申请

DELPHI安卓定位权限申请

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

1)静态申请定位权限:

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)运行效果图:

posted @ 2019-05-20 08:41  delphi中间件  阅读(966)  评论(0编辑  收藏  举报