首页 > 其他分享 >delphi11安卓权限的改变

delphi11安卓权限的改变

时间:2022-12-21 09:00:37浏览次数:41  
标签:RationaleMsg APermissions const delphi11 安卓 AGrantResults end 权限 procedure

delphi11安卓权限的改变

/// <author>cxg 2022-12-21</author>

unit uRights;

interface

uses
  System.Permissions,
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs
  , UI.Frame, UI.Standard, UI.Base
  ;

type
  TRights = class(TFrame)
    LinearLayout1: TLinearLayout;
    btnBack: TTextView;
    tvTitle: TTextView;
    ButtonView1: TButtonView;
    procedure btnBackClick(Sender: TObject);
    procedure ButtonView1Click(Sender: TObject);
  private
    { Private declarations }
    FPermissionCamera,
    FPermissionReadExternalStorage,
    FPermissionWriteExternalStorage: string;
    {$IF CompilerVersion >= 35.0}
    procedure TakePicturePermissionRequestResult(const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray);
    procedure DisplayRationale(const APermissions: TClassicStringDynArray; const APostRationaleProc: TProc);
    {$ELSE}
    procedure TakePicturePermissionRequestResult(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>);
    procedure DisplayRationale(const APermissions: TArray<string>; const APostRationaleProc: TProc);
    {$ENDIF}
  public
    { Public declarations }
    procedure DoCreate; override;
  end;

var
  Rights: TRights;

implementation

{$R *.fmx}

uses
  Androidapi.Jni.Os,
  Androidapi.Helpers;

procedure TRights.btnBackClick(Sender: TObject);
begin
  Finish;
end;

procedure TRights.ButtonView1Click(Sender: TObject);
begin
  FPermissionCamera := JStringToString(TJManifest_permission.JavaClass.CAMERA);
  FPermissionReadExternalStorage := JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE);
  FPermissionWriteExternalStorage := JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE);
  PermissionsService.RequestPermissions([FPermissionCamera, FPermissionReadExternalStorage, FPermissionWriteExternalStorage], TakePicturePermissionRequestResult, DisplayRationale);
end;

{$IF CompilerVersion >= 35.0}
procedure TRights.DisplayRationale(const APermissions: TClassicStringDynArray; const APostRationaleProc: TProc);
var
  I: Integer;
  RationaleMsg: string;
begin
  for I := 0 to High(APermissions) do
  begin
    if APermissions[I] = FPermissionCamera then
      RationaleMsg := RationaleMsg + '应用需要拍照' + SLineBreak + SLineBreak
    else if APermissions[I] = FPermissionReadExternalStorage then
      RationaleMsg := RationaleMsg + '应用需要读取照片';
  end;


  APostRationaleProc;
  ShowMessage(RationaleMsg);
end;
{$ELSE}
procedure TRights.DisplayRationale(Sender: TObject;
  const APermissions: TArray<string>; const APostRationaleProc: TProc);
var
  I: Integer;
  RationaleMsg: string;
begin
  for I := 0 to High(APermissions) do
  begin
    if APermissions[I] = FPermissionCamera then
      RationaleMsg := RationaleMsg + '应用需要拍照' + SLineBreak + SLineBreak
    else if APermissions[I] = FPermissionReadExternalStorage then
      RationaleMsg := RationaleMsg + '应用需要读取照片';
  end;


  APostRationaleProc;
  ShowMessage(RationaleMsg);
end;
{$ENDIF}

procedure TRights.DoCreate;
begin

end;

{$IF CompilerVersion >= 35.0}
procedure TRights.TakePicturePermissionRequestResult(
  const APermissions: TClassicStringDynArray;
  const AGrantResults: TClassicPermissionStatusDynArray);
begin
 // 申请的3个权限: CAMERA, READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE
  if (Length(AGrantResults) = 3) and (AGrantResults[0] = TPermissionStatus.Granted) and (AGrantResults[1] = TPermissionStatus.Granted) and (AGrantResults[2] = TPermissionStatus.Granted) then
  begin
    //权限被用户允许的代码
  end
  else
    //权限被用户禁止的代码
    ShowMessage('权限禁止,不能拍照.');
end;
{$ELSE}
procedure TRights.TakePicturePermissionRequestResult(
  const APermissions: TArray<string>;
  const AGrantResults: TArray<TPermissionStatus>);
begin
 // 申请的3个权限: CAMERA, READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE
  if (Length(AGrantResults) = 3) and (AGrantResults[0] = TPermissionStatus.Granted) and (AGrantResults[1] = TPermissionStatus.Granted) and (AGrantResults[2] = TPermissionStatus.Granted) then
  begin
    //权限被用户允许的代码
  end
  else
    //权限被用户禁止的代码
    ShowMessage('权限禁止,不能拍照.');
end;
{$ENDIF}

end.

 

标签:RationaleMsg,APermissions,const,delphi11,安卓,AGrantResults,end,权限,procedure
From: https://www.cnblogs.com/hnxxcxg/p/16995493.html

相关文章

  • D10.4开发的安卓程序,D11编译报错的解决方法
    D10.4开发的安卓程序,D11编译报错的解决方法如果用D11打开工程,10.4下很多自带的jar都已经被去除了如果立即编译的话,会报错:这个时候,你只要右键Libraries,在弹出的菜单中......
  • 安卓开发
    Prerequisite我要做一个视频类APP习惯参数左上角项目类别使用Android右侧视图的尺寸为:Pixel3XL,Android29xml布局最好从开头就用LinearLayout,否则可能因为尺寸......
  • Linux特殊权限 SUID、SGID、Sticky
    转载自:https://www.jianshu.com/p/5c1db5821a14在理解特殊权限之前,需要先具备几个关于安全上下文的认知:前提:进程有属主和属组;文件有属主和属组;任何一个可执行程序文......
  • 安卓-控件拖动
    一、安卓的当前控件移动可以通过: layoutcaseMotionEvent.ACTION_MOVE:intoffsetX=x-mLastX;intoffsetY=y-m......
  • Spring Security 动态url权限控制
    一、前言本篇文章将讲述SpringSecurity动态分配url权限,未登录权限控制,登录过后根据登录用户角色授予访问url权限基本环境 spring-boot2.1.8mybatis-plus2.2.0......
  • Linux 基础-文件权限与属性
    一,文件类型二,文件属性与权限三,Linux文件属性与权限总结四,参考资料Linux系统由Linux内核、shell、文件系统和第三方应用软件组成。Linux文件权限与属性是学习Li......
  • 【mysql-01】开放远程连接权限遇到的问题
    环境电脑本机ip:192.xxx.xxx.xxx虚拟机A的ip:192.168.132.100虚拟机B的ip:192.168.132.101虚拟机A上的mysql用户权限情况:如图,在虚拟机A上的mysql开放了本地电脑ip的......
  • 【FAQ】申请Health Kit权限的常见问题及解答
    华为运动健康服务(HUAWEIHealthKit)提供原子化数据开放,用户数据被授权获取后,应用可通过接口访问运动健康数据,对相关数据进行增、删、改、查等操作。这篇文章汇总了申请开通......
  • Spring Boot 之 RESRful API 权限控制
    一、为何用RESTfulAPI1.1RESTful是什么?RESTful(RepresentationalStateTransfer)架构风格,是一个Web自身的架构风格,底层主要基于HTTP协议(ps:提出者就是HTTP协议的作者),是分布......
  • 我的第一款安卓原生游戏之万变塔防(第一章)
    首先这款游戏是我的第一款游戏。这款游戏明确是收费的。收费总共有八个等级。最低收费是7元。第一级7元第二级14元第三级28元第四级56元第五级112元第六级224元第七级448元......