Recent

Author Topic: assets\files not accessible  (Read 315 times)

cbsistem

  • New Member
  • *
  • Posts: 39
assets\files not accessible
« on: February 21, 2020, 03:21:46 am »



files in the assets folder are not accessible
in the assets folder contains:

Code: Pascal  [Select][+][-]
  1. assets\databases\myData.db
  2. assets\test.txt

when the apk is generated the files are all inside it.

when you run the application I can't access these files.

I tried to use this code and it doesn't work


Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. var
  3.   pathToDB: string;
  4. begin
  5.    pathToDB:=Self.GetEnvironmentDirectoryPath(dirDatabase);
  6.    
  7.    if FileExists( pathToDB + '/' + 'myData.db' ) then   //  not found
  8.  
  9.     ShowMessage('file exists');
  10. end;



Code: Pascal  [Select][+][-]
  1. pathToDB:=GetFilePath(fpathApp);                            //    /data/app/org.lamw.applamwproject1-2/base.apk
  2. pathToDB:=Self.GetEnvironmentDirectoryPath(dirDatabase);    //    /data/user/0/org.lamw.applamwproject1/database
  3.  
  4. pathToDB:=GetFilePath(fpathData);                          //     /data/user/0/org.lamw.applamwproject1/files
  5. if FileExists(pathToDB+'/test.txt') then                  //  not found
  6.       jListView1.LoadFromFile('test.txt');
« Last Edit: February 21, 2020, 12:41:31 pm by cbsistem »

cbsistem

  • New Member
  • *
  • Posts: 39
Re: assets\files not accessible
« Reply #1 on: February 21, 2020, 02:34:57 pm »
One thing I identified was:
IT IS NOT JUST JUST PLACING THE FILE NOVA_IMAGEM.PNG in the ASSETS folder,
I needed to put it inside an ImageList so it will be available and be identified by the code below


Code: Pascal  [Select][+][-]
  1.      pathToDB: = GetFilePath (fpathData) + '/ test2.png';
  2.      if self.FileExists (pathToDB) then
  3.         ShowMessage ('exists test2.png');
  4.  

probably the same should happen with databases\myData.db
no folder just put it inside it must be linked to the component.


but what I need is to send a list of files, which can be HTML, JavaScript, Images
the questions are:
It is mandatory to link files to a component.
How could I send these files?


cbsistem

  • New Member
  • *
  • Posts: 39
Re: assets\files not accessible
« Reply #2 on: February 21, 2020, 04:26:10 pm »

SORTED OUT
the files in the assets folder are not visible to the FileExists method

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
  2.  
  3.   var
  4.     i: integer;
  5.     _FilesList:TStrings;
  6.     _pathTo, _file:string;
  7.   begin
  8.     //makes files in the assets folder accessible via the FileExists method
  9.    _pathTo:=GetFilePath(fpathData);
  10.    _FilesList:=TStringList.Create;
  11.    _FilesList.Add('teste.txt');    //add your files from the assets folder
  12.  
  13.     for i:= 0 to _FilesList.Count - 1 do
  14.     begin
  15.        _file:=Trim(_FilesList.Strings[i]);
  16.        if _file <> '' then
  17.        begin
  18.           if not FileExists(_pathTo+'/'+_file) then
  19.           Asset_SaveToFile(_file,_pathTo+'/'+_file);
  20.        end;
  21.     end;
  22. end;            

 

TinyPortal © 2005-2018