Recent

Author Topic: [SOLVED] WRITE_EXTERNEL_STORAGE Failed in ANDROID 14  (Read 8313 times)

Guser979

  • Jr. Member
  • **
  • Posts: 61
Re: [SOLVED] WRITE_EXTERNEL_STORAGE Failed in ANDROID 14
« Reply #15 on: July 28, 2024, 04:49:26 pm »


Solved using chatgpt's suggestion, but using only LAMW (no need to modify jform.java) to save the URI.

Code: Pascal  [Select][+][-]
  1.  
  2. //Delete files named filezip.zip
  3. // Add jpreferences component (Android Bridges Extra)
  4.  
  5. // Add URI verification
  6. procedure AndroidModule1.zip;
  7. ///// variables, etc
  8.  
  9. begin
  10. ///// ......here the code for compressing files generating "filezip.zip"
  11.  
  12. // Here check if the URI already exists.
  13. // If URI does not exist then create "filezip.zip"
  14. // If URI exists then open file "filezip.zip" and it will be overwritten
  15.  
  16. if Preferences1.GetStringData('uri','') <> '' then self.RequestOpenFile(Self.GetEnvironmentDirectoryPath(dirDownloads),'application/zip' ,112) else  Self.RequestCreateFile(Self.GetEnvironmentDirectoryPath(dirDownloads),'application/zip','filezip.zip', 111);
  17.  
  18. end;
  19.  
  20. // Here is where we first register the URI in preferences after "Create intent"
  21.  
  22.  
  23.  
  24. procedure TAndroidModule1.AndroidModule1ActivityResult(Sender: TObject;
  25.   requestCode: integer; resultCode: TAndroidResult; intentData: jObject);
  26.  
  27.   var arrayb: Tdynarrayofjbyte;
  28.    treeUri : jObject;
  29.    fs:tfilestream;                    
  30.  
  31. begin                                  
  32.  if intentData = nil then
  33.       begin
  34.          ShowMessage('Sorry... data nil received...');
  35.          Exit;
  36.       end;
  37.  
  38.       treeUri:= IntentManager1.GetDataUri(intentData);
  39.  
  40.  if requestCode = 111 then  //create file
  41.    begin
  42.     //   Save URI
  43.         Preferences1.SetStringData('uri',UriToString(treeUri));
  44.    
  45.         FS := TFileStream.Create(GetEnvironmentDirectoryPath(dirDownloads)+'/filezip.zip', fmOpenRead or fmShareDenyWrite);
  46.     SetLength( arrayb, fs.Size);   fs.Position:=0;
  47.     Fs.Read(arrayb[0], fs.Size);
  48.     SaveBytesToUri(arrayb,treeUri);
  49.     FS.Free;
  50.   end;
  51.  
  52.  if requestCode = 112 then  //open  file
  53.   begin
  54.     FS := TFileStream.Create(GetEnvironmentDirectoryPath(dirDownloads)+'/filezip.zip', fmOpenRead or fmShareDenyWrite);
  55.     SetLength( arrayb, fs.Size);   fs.Position:=0;
  56.     Fs.Read(arrayb[0], fs.Size);
  57.     SaveBytesToUri(arrayb,treeUri);
  58.     FS.Free;
  59.   end;
  60.  
  61.  end;
  62.  
  63.  
  64.  
« Last Edit: July 28, 2024, 06:45:53 pm by Guser979 »

Guser979

  • Jr. Member
  • **
  • Posts: 61
Re: [SOLVED] WRITE_EXTERNEL_STORAGE Failed in ANDROID 14
« Reply #16 on: July 28, 2024, 07:02:30 pm »
Could you please help me by modifying my application? I can't understand where the java code should be added. I tried adding it to the jform.java file but it deletes it in the compile.
Thanks in advance for your time


The LAMW installed on my PC can't open your project, causing an "Access violation" error.

But with the latest modification you will be able to get what you need without modifying jform.java.

Unfortunately Android 14 has restrictions on handling files. For now this is what I managed to get working here, regarding this.

magleft

  • Full Member
  • ***
  • Posts: 121
Re: [SOLVED] WRITE_EXTERNEL_STORAGE Failed in ANDROID 14
« Reply #17 on: July 28, 2024, 07:41:38 pm »
Thank you very much .
I'll test it and update.
windows 10 64

magleft

  • Full Member
  • ***
  • Posts: 121
Re: [SOLVED] WRITE_EXTERNEL_STORAGE Failed in ANDROID 14
« Reply #18 on: July 29, 2024, 05:18:00 pm »
Works!!!!
Thanks. Very good work.
Thanks again.
windows 10 64

 

TinyPortal © 2005-2018