Jump to content
Sign in to follow this  
PavelX

10.4 firemonkey 10.4 failed to create folder on android

Recommended Posts

Hi,

 

I try to run the following code on Android (10.4 Sydney)

 

fn:=TPath.Combine(TPath.GetSharedDocumentsPath(),'OLA');

TDirectory.CreateDirectory(fn); // or ForceDirectories(fn) -> I tried both functions
 if TDirectory.Exists(fn,false) then
    showmessage('Ok')
  else
    showmessage('Failed');

 

And the code fail. The same code works without any problem with 10.3.3 (using the same phone)

 

Note:

On both environments I have used default User Permissions. including "Write external storage" 

 

Did you encountered this problem? - how did you solved?

 

Thank you in advance,

Pavel

 

 

 

Edited by PavelX

Share this post


Link to post

The following worked fine for me:

procedure TForm1.Button1Click(Sender: TObject);
begin
  PermissionsService.RequestPermissions(['android.permission.READ_EXTERNAL_STORAGE', 'android.permission.WRITE_EXTERNAL_STORAGE'],
    procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
    begin
      // NOTE: I am assuming the user granted permission, here!
      CreateFolder;
    end
  );
end;

procedure TForm1.CreateFolder;
var
  fn: string;
begin
  fn := TPath.Combine(TPath.GetSharedDocumentsPath, 'OLA');
  ForceDirectories(fn);
  if TDirectory.Exists(fn) then
    Button1.Text := 'OK'
  else
    Button1.Text := 'Failed';
end;

Delphi 10.4.1, Android 11 device (Pixel3a)

  • Like 1

Share this post


Link to post

Dave, first of all I want to thank you for your fast reply.

It looks that that you have right. Indeed environment  User Permissions has no effect

 

Thanks again,

Pavel

 

Share this post


Link to post
25 minutes ago, PavelX said:

Indeed environment  User Permissions has no effect

It will not work if you do not have the permissions checked in the project options.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×