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

Posted by on in Blogs
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
About
Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.
Comments are not available for public users. Please login first to view / add comments.