• delphi给App授予权限


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

    第一步:

      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:


      

  • 相关阅读:
    Linux基础命令---arch
    JSON漫谈
    django中外键关联表的查询随笔
    <django中render_to_response的可选参数和使用方法>
    有趣的Redis:缓存被我写满了,该怎么办?
    2020全球C++及系统软件技术大会成功落下帷幕
    AWS 宣布创建 Elasticsearch 和 Kibana 分支
    Flutter开发指南之理论篇:Dart语法05(单线程模型,事件循环模型,Isolate)
    自定义注解!绝对是程序员装逼的利器!!
    Java8 Stream
  • 原文地址:https://www.cnblogs.com/karkash/p/15717593.html
Copyright © 2020-2023  润新知