Skip to content

Delphi XE5 - deploying and accessing local files on iOS and Android

Larry in Canada recently sent me an email asking a Delphi XE5 mobile multi-device question: "How do you include files and/or folders containing files with a Delphi Android application APK file?" I told him I would create a simple example and explain how deploy a file with your application and then access it from a Delphi app for iOS and Android. To accomplish this, you create a new mobile app, write one or more lines of code, the Project | Deployment menu item and use the System.IOUtils unit’s TPath.GetDocumentsPath method and PathDelim in your code.

The steps I followed to create my sample mobile app

1) File | New | FireMonkey Mobile Application - Delphi and used the "Blank Application" project template.

2) On the form, I added 1 TButton, 2 TLabel and 1 TImage components.

3) I double clicked on the TButton component to create the OnClick event handler.

4) I added a "uses System.IOUtils;" just below the {$R *.fmx} in the implementation section.

5) I added the following code in the event handler to display the documents path and to load the bitmap from the documents folder:

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      DocPathLabel.Text := TPath.GetDocumentsPath;
      Image1.Bitmap.LoadFromFile(TPath.GetDocumentsPath + PathDelim + 'davidi_tiedye.jpg');
    end;

6) In the Project Manager, I added Android and iOS Target Platforms so that I can build for each of the two platforms.

7) Using the Project | Deployment menu item, I chose the Android and the iOS Device platforms and for each one I clicked on the "Add Files" button in the local toolbar to select the bitmap file I want to deploy with my app and set the Remote Path column value:

    For Android, set the Remote Path to assets\internal
    For iOS, set the Remote Path to StartUp\Documents

Here are screen shots of each of the resulting Deployment settings:

7) Compile, Deploy and Run the app on Android (I used my Samsung Galaxy S4) and iOS (I used my iPhone 4s) producing the following result when I click on the Button:

You can read additional information about mobile application development and deployment on the Embarcadero DocWiki using the following URLs:

If you don’t have Delphi or RAD Studio XE5 you can download the free trial at http://www.embarcadero.com/products/rad-studio/downloads

{ 8 } Comments

  1. Reza | January 27, 2014 at 10:14 am | Permalink

    Hi
    I try to deploy file on ios, startUp\Documents is OK on simulator but on the device there is below file structure
    MyApp.app
    +Documents
    +MyApp.app
    ++Startup
    +++Documents
    ++++MyDBFile

    MyDBFile is deployed in wrong folder, when I copy the file to the first Documents folder every ting is OK, I tried .\Startup\Documents and .\Documents and \Documents but nothing is changed. Any idea?

  2. David I | January 27, 2014 at 11:16 am | Permalink

    Reza - make sure your directory names are case sensitive. The iOS Simulator accepts upper and lower case as the same. The iOS device does not. So…

    StartUp\Documents

    is not the same on and iOS device as

    Startup\Documents

  3. Reza | January 30, 2014 at 6:08 am | Permalink

    Hi David

    I tried StartUp\Documents but nothing is changed, on the device this is file structure
    MyApp.app
    +Documents
    +MyApp.app
    ++StartUp
    +++Documents
    ++++MyDBFile

    Do I miss something, I can send you some screen shot.

  4. Reza | January 30, 2014 at 6:28 am | Permalink

    Hi David
    Although file MyDBFile is not in Documents folder but when I run my app it will copy it from wrong folder to the correct folder and it works fine.

    Thnaks

  5. Patrick Stack | January 30, 2014 at 6:34 am | Permalink

    I had a similar issue with files not being deployed. I was able to fix it by deleting all of the files in the scratch-dir on the MAC. Then build and deploy again.

  6. Lionel | March 21, 2014 at 9:40 am | Permalink

    Hello,

    I have a problem about updating this file.. If i create a file in document forder, like a TEXT file, when i compile my program, the Uninstall / Install Process delete my file.

    Can you give Solution to create files able to SURVIVE the UnInstall/Install process.

    Thanks….

  7. bear | May 24, 2014 at 4:32 am | Permalink

    For Android, set the Remote Path to assets\internal ==>assets\internal\
    For iOS, set the Remote Path to StartUp\Documents ==>StartUp\Documents\

  8. ugruu | July 11, 2014 at 12:02 am | Permalink

    thanks good job

{ 2 } Trackbacks

  1. [...] TIniFile and TMemIniFile to save settings on Android just like you would on Windows. Be sure to use TPath.GetDocumentsPath + PathDelim to get the right location to save your Ini file to. A second way to save settings would be with [...]

  2. [...] TIniFile and TMemIniFile to save settings on Android just like you would on Windows. Be sure to use TPath.GetDocumentsPath + PathDelim to get the right location to save your Ini file to. A second way to save settings would be with [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

Bad Behavior has blocked 4 access attempts in the last 7 days.

Close