procedure TCCAMap.StartLocation(); begin {$IFDEF ANDROID} PermissionsService.RequestPermissions([ JStringToString(TJManifest_permission.JavaClass.ACCESS_COARSE_LOCATION), JStringToString(TJManifest_permission.JavaClass.ACCESS_FINE_LOCATION) ], procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>) begin if (Length(AGrantResults) = 2) and (AGrantResults[0]=TPermissionStatus.Granted) and (AGrantResults[1]=TPermissionStatus.Granted) then begin FJAMap.StartLocation; end; end); {$ENDIF} end;
上面是改造后的代码,增加动态申请需要的权限。
为什么要这样呢?我在上架小米应用时遇到这样的问题:
没办法,只好这样改造了,这样,就不用在应用启动时申请位置权限。