Create CSV lazarus / 43-Android ---------------------------------------------------------------------- xinyiman · 2021-12-06 14:11 Hello to all. Can anyone tell me how I can export a csv file to the Download folder? Thanks ---------------------------------------------------------------------- loaded · 2021-12-06 15:38 Hi , lazandroidmodulewizard-master\demos\GUI\AppDownloadManagerDemo1 I think you can do whatever you want with the sample project. ---------------------------------------------------------------------- jmpessoa · 2021-12-06 20:04 Quotehow I can export a csv file to the Download folder... That is,  save some csv/txt content to a  file in device Download folder? ---------------------------------------------------------------------- xinyiman · 2021-12-07 07:39 Yes. I test this code. But not create a file. filename   := self.GetEnvironmentDirectoryPath(dirDownloads) + System.DirectorySeparator + 'abcd.csv'; Self.jListView1.SaveToFile(filename); ---------------------------------------------------------------------- jmpessoa · 2021-12-07 17:21 Maybe, our app can not save to "public" folder anymore.... The system is imposing new restrictions with each new Android version.. Can you test in some "old" device? What about jTextFileManager? can you do some test? ---------------------------------------------------------------------- Leledumbo · 2021-12-09 04:53 You need WRITE_EXTERNAL_STORAGE in the manifest these days. Well, depending on the target API. ---------------------------------------------------------------------- xinyiman · 2022-02-10 16:00 With this code my app crash. Why? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModuleMain.Btn_EsportaClick(Sender: TObject);var   nome_file : string;begin      if not IsRuntimePermissionGranted('android.permiss ion.WRITE_EXTERNAL_STORAGE') then     begin          ShowMessage('Sorry... Some Runtime Permission NOT Granted ...');        Exit;     end;      nome_file   := self.GetEnvironmentDirectoryPath(dirDownloads) + System.DirectorySeparator + 'letture_barcode.csv';     if FileExists(nome_file) then     begin          DeleteFile(nome_file);   end;     Self.jTextFileManager1.SaveToFile('hello world', nome_file);     ShowLog('Esportato in: ' + nome_file);end; ---------------------------------------------------------------------- jmpessoa · 2022-02-10 18:52 Hi, xinyiman! Android 11 - Api 30  has restricted developers to access devices "publics" folders (ex: "Download, Documents, ..., etc") Developers no longer have access to a file via its path. Instead, you need to use via “Uri“. New!   jForm methods:  //get user permission... and an uri RequestCreateFile RequestOpenFile RequestOpenDirectory procedure TakePersistableUriPermission  //handling file by uri....  function GetFileList                [edited...]  function GetBitmapFromUri  function GetTextFromUri  procedure SaveImageToUri  procedure SaveTextToUri New demo: "AppPublicFoldersAccessDemo1" ---------------------------------------------------------------------- xinyiman · 2022-02-10 19:49 Ok it works. Just one problem. It appears that saving the data with SaveTextToUri is asynchronous. It took several seconds to write 12 lines. Do you know why? ---------------------------------------------------------------------- xinyiman · 2022-02-10 20:02 Correct me, it's not asynchronous. It does not save the data in the file unless I change the screen. Do you know how to make it immediate? ---------------------------------------------------------------------- Insid3Code · 2022-02-10 21:09 The crash is due to: path separator "/" Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i java.lang.IllegalArgumentException: File /storage/emulated/0/Download/letture_barcode.csv contains a path separator  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i public void SaveToFile(String _txtContent, String _filename) {              try {         OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput(_filename, Context.MODE_PRIVATE));.........     }     catch (IOException e) { ...     }} openFileOutput don't accept "/" path separator. You can fix your snippet like this: jTextFileManager1.SaveToFile('hello world', Path, nome_file); Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.Button1Click(Sender: TObject);var  nome_file, Path: string;begin  nome_file := '/letture_barcode.csv';  if not IsRuntimePe rmissionGranted('android.permission.WRITE_EXTERNAL_STORAGE') then  begin    ShowMessage('Sorry... Some Runtime Permission NOT Granted ...');    Exit;  end;   Path := self.GetEnvironmentDirectoryPath(dirDownloads);   if FileExists(Path + nome_file) then  begin    DeleteFile(nome_file);  end;   jTextFileManager1.SaveToFile('hello world', Path, nome_file);   if FileExists(Path + nome_file) then  begin    ShowMessage('Done!');  end;end;                               Animated gif as demo Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i public void SaveToFile(String _txtContent, String _path, String _filename){      FileWriter fWriter;             try{ // Environment.getExternalStorageDirectory().getPath()             fWriter = new FileWriter(_path +"/"+ _filename);             fWriter.write(_txtContent);             fWriter.flush();             fWriter.close();         }catch(Exception e){             e.printStackTrace();         }} ---------------------------------------------------------------------- xinyiman · 2022-02-11 07:43 You're right, it works. But now I'm curious to know why the solution proposed by jmpessoa creates the empty file and fills it only after I interact with other forms of the project.