DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: helim520
今日帖子: 23
在线用户: 12
导航: 论坛 -> 移动应用开发 斑竹:flyers,iamdream  
作者:
男 stacker (OOP才是王道) ★☆☆☆☆ -
普通会员
2019/4/16 11:40:49
标题:
为什么此程式在10.3.1底下可以存取相簿郤无法存取相机? 浏览:196
加入我的收藏
楼主: 如题,程式外面权限已经设定了。


unit utCameraSamples;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.Permissions,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.MediaLibrary, FMX.Platform, System.Messaging,
  FMX.Objects, FMX.StdCtrls, FMX.Controls.Presentation,
  FMX.MediaLibrary.Actions, System.Actions, FMX.ActnList, FMX.StdActns,
  FMX.Effects, FMX.Layouts;

type
  TCameraSamplesForm = class(TForm)
    CameraSamplesToolBar: TToolBar;
    CameraSamplesCameraSpeedButton: TSpeedButton;
    CameraSamplesSearchSpeedButton: TSpeedButton;
    CameraSamplesImage: TImage;
    CameraSamplesImageLayout: TLayout;
    CameraSamplesToolBarShadowEffect: TShadowEffect;
    CameraSamplesToolBarTitleLabel: TLabel;
    CameraSamplesStyleBook: TStyleBook;
    CameraSamplesActionList: TActionList;
    CameraSamplesTakePhotoFromLibraryAction: TTakePhotoFromLibraryAction;
    CameraSamplesTakePhotoFromCameraAction: TTakePhotoFromCameraAction;
    procedure CameraSamplesCameraSpeedButtonClick(Sender: TObject);
    procedure CameraSamplesSearchSpeedButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CameraSamplesTakePhotoFromLibraryActionDidFinishTaking(Image: TBitmap);
    procedure CameraSamplesTakePhotoFromCameraActionDidFinishTaking(Image: TBitmap);
  private
    { Private declarations }
    FPermissionCamera: string;
    FPermissionReadExternalStorage: string;
    FPermissionWriteExternalStorage: string;
    procedure CameraSamplesDoDidFinish(Image: TBitmap);
    procedure CameraSamplesDoDisplayRationale(Sender: TObject; const APermissions: TArray<string>; const APostRationaleProc: TProc);
    procedure CameraSamplesDoTakePicturePermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>);
    procedure CameraSamplesDoSearchPicturePermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>);
  public
    { Public declarations }
  end;

var
  CameraSamplesForm: TCameraSamplesForm;

implementation

uses
  {$IFDEF ANDROID}
  Androidapi.Helpers,
  Androidapi.JNI.JavaTypes,
  Androidapi.JNI.Os,
  {$ENDIF}
  FMX.DialogService;

{$R *.fmx}
{ TCameraSamplesForm }

procedure TCameraSamplesForm.CameraSamplesCameraSpeedButtonClick(Sender: TObject);
begin
  PermissionsService.RequestPermissions([FPermissionCamera, FPermissionReadExternalStorage, FPermissionWriteExternalStorage], CameraSamplesDoTakePicturePermissionRequestResult, CameraSamplesDoDisplayRationale)
end;

procedure TCameraSamplesForm.CameraSamplesDoDidFinish(Image: TBitmap);
begin
  CameraSamplesImage.Bitmap.Assign(Image);
end;

procedure TCameraSamplesForm.CameraSamplesDoDisplayRationale(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 + 'The App Needs To Access The Camera To Take A Photo' + sLineBreak
    else
    begin
      if APermissions[I] = FPermissionReadExternalStorage then
        RationaleMsg := RationaleMsg + 'The App Needs To Read A Photo File From Your Device' + sLineBreak
      else
      begin
        if APermissions[I] = FPermissionWriteExternalStorage then
          RationaleMsg := RationaleMsg + 'The App Needs To Write A Photo File To Your Device' + sLineBreak;
      end;
    end;
  end;

  // Show an explanation to the user *asynchronously* - don't block this thread waiting for the user's response!
  // After the user sees the explanation, invoke the post-rationale routine to request the permissions
  TDialogService.ShowMessage(RationaleMsg,
    procedure(const AResult: TModalResult)
    begin
      APostRationaleProc;
    end)
end;

procedure TCameraSamplesForm.CameraSamplesDoSearchPicturePermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>);
begin
  // 3 permissions involved: 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
    CameraSamplesTakePhotoFromLibraryAction.Execute;
  end
  else
    TDialogService.ShowMessage('Cannot Read A Photo Due To The Required Permissions Are Not All Granted')
end;

procedure TCameraSamplesForm.CameraSamplesDoTakePicturePermissionRequestResult(Sender: TObject; const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>);
begin
  // 3 permissions involved: 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
    CameraSamplesTakePhotoFromCameraAction.Execute;
  end
  else
    TDialogService.ShowMessage('Cannot Take A Photo Due To The Required Permissions Are Not All Granted')
end;

procedure TCameraSamplesForm.CameraSamplesSearchSpeedButtonClick(Sender: TObject);
begin
  PermissionsService.RequestPermissions([FPermissionCamera, FPermissionReadExternalStorage, FPermissionWriteExternalStorage], CameraSamplesDoSearchPicturePermissionRequestResult, CameraSamplesDoDisplayRationale)
end;

procedure TCameraSamplesForm.CameraSamplesTakePhotoFromCameraActionDidFinishTaking(Image: TBitmap);
begin
  CameraSamplesDoDidFinish(Image);
end;

procedure TCameraSamplesForm.CameraSamplesTakePhotoFromLibraryActionDidFinishTaking(Image: TBitmap);
begin
  CameraSamplesDoDidFinish(Image);
end;

procedure TCameraSamplesForm.FormCreate(Sender: TObject);
begin
  {$IFDEF ANDROID}
  FPermissionCamera := JStringToString(TJManifest_permission.JavaClass.CAMERA);
  FPermissionReadExternalStorage := JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE);
  FPermissionWriteExternalStorage := JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE);
  {$ENDIF}
end;

end.


按相机时会出现爪哇错误
----------------------------------------------
-
作者:
男 wang_80919 (Flying Wang) ▲▲▲▲▲ -
普通会员
2019/4/16 12:00:30
1楼: 新版本 需要 动态权限。
不仅仅如此
文件必须 先通过 XML 注册共享。
----------------------------------------------
(C)(P)Flying Wang
作者:
男 stacker (OOP才是王道) ★☆☆☆☆ -
普通会员
2019/4/16 14:04:54
2楼: 我是根据10.3.1里的范例来修改的,该范例是没有问题的。
----------------------------------------------
-
作者:
男 stacker (OOP才是王道) ★☆☆☆☆ -
普通会员
2019/4/16 14:08:30
3楼: 要如何做XML注册共享?
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v2.1 版权所有 页面执行39.0625毫秒 RSS