• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

delphi给App授予权限

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

首先要切换到安卓平台下:

 

 

第一步:

  Project — Options — Application — Uses Permissions:

 

  •  注意如下图:产生费用的功能 要谨慎勾选——打电话、发送短信…

 

 

第二步:

引用权限单元UnitPermission:(Alt+F11)

unit UnitPermission;

interface

uses
{$IFDEF ANDROID} Androidapi.Helpers,
 Androidapi.JNI.JavaTypes, Androidapi.JNI.OS, {$ENDIF}
  System.Permissions;

function RequestLocation: Boolean;
function RequestRecordAudio: Boolean;
function RequestCamera: Boolean;
function RequestReadStorage: Boolean;
function RequestWriteStorage: Boolean;
function RequestSendSMS:Boolean;
function RequestReadPhoneState:Boolean;

implementation

function RequestReadPhoneState: Boolean;
var
  Value: Boolean;
begin
  Value := False;

{$IFDEF ANDROID}
  PermissionsService.RequestPermissions(
  [JStringToString(TJManifest_permission.JavaClass.READ_PHONE_STATE)],
    procedure(const APermissions: TArray<string>;
     const AGrantResults: TArray<TPermissionStatus>)
    begin
      if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
      begin
        Value := (True);
      end
      else
      begin
        Value := (False);
      end;
    end);
{$ENDIF}
  Result := Value;
end;


function RequestLocation: Boolean;
var
  Value: Boolean;
begin
  Value := False;

{$IFDEF ANDROID}
  PermissionsService.RequestPermissions(
  [JStringToString(TJManifest_permission.JavaClass.ACCESS_FINE_LOCATION)],
    procedure(const APermissions: TArray<string>;
     const AGrantResults: TArray<TPermissionStatus>)
    begin
      if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
      begin
        Value := (True);
      end
      else
      begin
        Value := (False);
      end;
    end);
{$ENDIF}
  Result := Value;
end;

function RequestRecordAudio: Boolean;
var
  Value: Boolean;
begin
  Value := False;
{$IFDEF ANDROID}
  PermissionsService.RequestPermissions([JStringToString(TJManifest_permission.JavaClass.RECORD_AUDIO)],
    procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
    begin
      if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
      begin
        Value := (True);
      end
      else
      begin
        Value := (False);
      end;
    end);
{$ENDIF}
  Result := Value;
end;

function RequestCamera: Boolean;
var
  Value: Boolean;
begin
  Value := False;
{$IFDEF ANDROID}
  PermissionsService.RequestPermissions([JStringToString(TJManifest_permission.JavaClass.CAMERA)],
    procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
    begin
      if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
      begin
        Value := (True);
      end
      else
      begin
        Value := (False);
      end;
    end);
{$ENDIF}
  Result := Value;

end;

function RequestReadStorage: Boolean;
var
  Value: Boolean;
begin
  Value := False;
{$IFDEF ANDROID}
  PermissionsService.RequestPermissions([JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE)],
    procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
    begin
      if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
      begin
        Value := (True);
      end
      else
      begin
        Value := (False);
      end;
    end);
{$ENDIF}
  Result := Value;
end;

function RequestWriteStorage: Boolean;
var
  Value: Boolean;
begin
  Value := False;
{$IFDEF ANDROID}
  PermissionsService.RequestPermissions([JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE)],
    procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
    begin
      if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
      begin
        Value := (True);
      end
      else
      begin
        Value := (False);
      end;
    end);
{$ENDIF}
  Result := Value;
end;

function RequestSendSMS:Boolean;
var
  Value: Boolean;
begin
  Value := False;
{$IFDEF ANDROID}
  PermissionsService.RequestPermissions([JStringToString(TJManifest_permission.JavaClass.SEND_SMS)],
    procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
    begin
      if (Length(AGrantResults) = 1) and (AGrantResults[0] = TPermissionStatus.Granted) then
      begin
        Value := (True);
      end
      else
      begin
        Value := (False);
      end;
    end);
{$ENDIF}
  Result := Value;
end;

end.

 

更改授权功能,对下图 红框中的 进行更改,还有其他一些小地方自己更改下就可以了

 

 把空格的地方 换作 下划线_ ;其他功能都类似:

 

 

最后注意:

如果按照上述方法 授权,功能仍不可用的话, 尝试勾选 下面这个
Project——Options——Application——Entitlement List:

 

 


  


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap