This is the blog of Brian Long, Windows & mobile trainer, trouble-shooter and consultant.
Friday, 14 February 2020
25 Delphi Tips for 25 Years of Delphi
As it happens I've been part of the Delphi world for around 26 years now, as I used to work at Borland and was involved with testing and experimenting with and working with the pre-release versions.
What can I say other than Happy Birthday, Delphi? You've been a good friend to me over this last quarter of a century and I've been happy to be part of your world.
Some number of posts ago I wrote up 10 Tips for Delphi Users. When I checked I was horrified to find this was 7 years ago! (My, my, how time flies when you're having fun...) Anyway, I thought I'd take that list and build upon it, expanding it up to 25 tips for Delphi users, which is what we have here. So without further ado let's get straight into the list.
Wednesday, 12 February 2020
The Enter key and the OnKeyDown/OnKeyUp events on Android
OnKeyDown and OnKeyUp events. This was unfortunate as Tom wanted to code to run in (one of) those handlers.The problem had been reported as RSP-27496 but alas it had been closed at the time Tom was hunting for a solution (to my mind closed wrongly).
What to do?
Well, after some valiant fighting with the problem accompanied with the inevitable wailing and gnashing of teeth, Tom found a workaround of sorts. Setting the
TEdit control's ReturnKeyType property Go, Search or Send allows the OnKeyDown event to fire for the Enter key. Good stuff! But not ideal....I sent a note to a relevant party within EMBT and after reviewing the report it has since been re-opened. That's a start.
Tuesday, 11 February 2020
C++Builder's Android location sensor woes
If you make a new Multi-Device Application in C++Builder and build it, all will be well, of course. The basics work very nicely.
If you now drop a
TLocationSensor component on the form and try to build now, the result will be different. Compilation goes fine. Linking looks like it is going fine.... until it fails with a rather unhelpful message:[ldandroid Error] "ld" exited with code 1.
Let's look at how we can get more useful feedback from this rather opaque and somewhat 1990s error message and see how to resolve the underlying problem.
Rebuilding the Delphi & C++Builder Android Java files
The script would rebuild all the Java files into the required fmx.dex.jar and fmx.jar archives and copy them into the relevant RAD Studio installation folders to be used on subsequent builds.
When I tried to use the script with RAD Studio 10.3.3 of course it didn't work as things have changed, different files need to be involved in the process. I have updated the script now to work with RAD Studio 10.3.3 and thought I'd share it in case anyone else needs to do this.
An obvious question is: Why would anyone else want to rebuild the Java Android RTL files? Well this is normally a necessary step if you find an issue in the code as Embarcadero ships it and you want to try to fix it or enhance it. Indeed the previous post on rebuilding the 10.3 Java files was all about patching the Java code to get Android
Intent support working.If you have no interest in tweaking the Java code or fixing any issues you encounter in the Java code then you probably won't be needing this script.
If you do need the script, remember to take a backup of your original compiled archives before you proceed. These are found in:
- C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\debug\fmx.jar
- C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\debug\fmx.dex.jar
- C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\release\fmx.jar
- C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\release\fmx.dex.jar
The script needs to be run from an administrative command prompt and before you run it you should double-check the various paths set up in the environment variables at the start are all valid on your system.
Thursday, 22 November 2018
RAD Studio 10.3 Rio supports Android runtime permissions
RAD Studio 10.3 Rio has just been released for General Availability, as you’ll have doubtless learned from the spree of blog posts on the subject. This is a great new release with a lot of bug fixes and some nice updates to product behaviour and features.
One feature that seems to have not received its fair share of attention in the documentation is the support for the Android 6.0 (and later) runtime permissions model. This caused a bit of frustration earlier in the year when Google changed the Play Store submission rules so that from August 2018 new apps have to follow this new permissions model and from November 2018 app updates also new apps have to.
RAD Studio 10.3 enhances the basic Android support to ensure that Android apps built with Delphi or C++ now understand and can support this new model, which may require a bit of change to your application logic.
In essence, instead of all permissions being granted on application installation, so-called dangerous permissions now need to be requested at runtime where the user can grant or deny them as they see fit. Additionally the user can change their mind in the app settings and toggle the permissions at any time.
The Android RTL has been enhanced with a framework to support requesting permissions at runtime and being notified of the user’s decision, and potentially offering a little explanation for the need for the permission.
As mentioned the documentation for this framework falls a little short right now (at product launch), but hopefully will improve over time. To try and plug the gap I’ve written an article showing how the permission framework can be used, both in Delphi and in C++. If interested in learning more about the Android runtime permission framework introduced in RAD Studio 10.3 Rio, please follow one of these links:
Finally, while I have your attention on things Android, I would like to draw your attention to the Android-specific release notes for RAD Studio 10.3. You should read these to be sure of getting on with your first Android project with the new product release. It needs and uses a later Android SDK and NDK and you mat encounter some teething niggles on installation. These notes should help you!
Saturday, 14 October 2017
Delphi build/install/launch Android app from the command-line
Quite some while back I answered a question on Stack Overflow, which explained how to build a Delphi project from the command line and also how to deploy it. The context of the question was Andriod development
In the case of an Android application deploying it has absolutely nothing to do with installing the resultant .apk file onto your Android device, despite what your personal interpretation of the word may be. Oh no, most definitely not.
Instead, deployment is about packaging up all your various files - your compiled Android library (a .so file), all the images, splash screens, icons, custom files, databases, application manifest file and so forth – all into an .apk file. In other words as far as the Delphi IDE is concerned, deploying a Delphi project means going from a .so native ARM library to an installable .apk file.
Clearly when you press F9 or Ctrl+Shift+F9 to run your application the IDE works out how to install your .apk on the currently connected and selected device, but that is subsequent to the IDE’s notion of the deployment step.
So, installation notwithstanding, that SO answer shows how to make/build and deploy a Delphi project, such as an Android project, from a RAD Studio command prompt:
Tuesday, 22 November 2016
Debug logging in FireMonkey – CodeRage XI Lightning Talks
During CodeRage XI I had a couple of Lightning Talks broadcast on a subject I’ve been intending to write up for quite a long time, but haven’t quite managed to achieve: how to emit debug log messages on the various FireMonkey platforms.
I made a 10 minute video for Delphi and one for C++ looking at all the target platforms, Win32/Win64, OS X/macOS, Android and iOS, showing the logging options and then looking at how to view log output.
Unfortunately I got a bit caught up in some work and didn’t publicise this ahead of the conference, so I think not many people were aware of them.
Friday, 9 September 2016
Android callbacks wrapped by FireMonkey
A couple of years ago (exactly!) I posted on this blog about an article I’d written on accessing NFC tags from Delphi Android applications. At the time this was quite an involved exercise, requiring custom Java code to be compiled and linked in to the application in order to respond to the pertinent Android callback, Activity.onNewIntent. Indeed, Delphi versions XE5, XE6 and XE7 all have slightly differing capabilities, with each new release making certain Android operations rather easier.
While catching up on what’s new in recent releases of Delphi I realised a change had been snuck into Delphi 10 Seattle that makes the whole NFC exercise much more straightforward now in Delphi.
Thursday, 1 September 2016
Speaking at the SDN Event
All the preparations are nigh on complete and this evening I shall be on a short aeroplane ride to Holland (or The Netherlands, if you prefer) to present a couple of Delphi talks at one of the SDN’s big SDN Events – full agenda here. I’ll be in good company as also speaking on the Delphi track will be TMS Software’s Bruno Fierens and also Bob Swart.
I’ve spoken at User Groups regularly but this is the first opportunity for me to talk to Delphi developers from further afield at a conference since April 2015 when I was at the ADUG Symposium, speaking in Canberra and Melbourne.
SDN events are always friendly gatherings and I’ve spoken at a few of them over the years: 1997, 1999, 2002, 2005, 2006 and 2012.
This time around I will be speaking on two of my favourite subjects: creative debugging techniques and accessing the Android OS API. Naturally I’ll be using the latest and greates version of Delphi as a vehicle for the talks, and I’ll be trying to squeeze in as many technical tips, tricks and techniques as I can into the 2 hour-long sessions.
For those attending the event tomorrow (2nd September, 2016) I’ll see you there!
Tuesday, 3 February 2015
Off to Australia to talk at ADUG Symposium 2015
I’m delighted to be able to announce that I’m off to Australia in March to do some talks at the ADUG Symposium 2015!
It’s a long way to travel, but I’m really looking forward to talking to the ADUG members about Delphi XE7 in both Melbourne and Canberra.
I’ve got a couple of talks scheduled in. I’ll be talking about consuming Android OS features that are outside the scope of what the FMX framework wraps up, and also looking at creative debugging techniques.
Hopefully I’ll manage to shed the jetlag in the few days prior to the event, when I shall be enjoying the delights of Melbourne, and then after the 2 events I’ll soak up Canberra before returning back to normality.
Thanks for inviting me along, ADUG – I can’t wait to join you in Australia!
Delphi and Android services (part 3)
Once upon a time I uploaded a Delphi sample app to the Google Play Store, written in Delphi XE5 and implementing an Android service. I wrote about the published app in this post and supplied the source in this follow-up post.
There was an issue that’s been hanging around with that sample project. When pulled into Delphi XE7 and updated so it all compiled nicely, it didn’t play ball when deployed. Instead it hung.
I’ve eventually worked through the to-do list enough to take a look at the problem. For one reason or another starting the service in the OnCreate event handler caused an issue thanks to some required thread synchronisation, which no longer functions as I wanted it to.
I’ve worked around the problem by very slightly delaying the service starting by use of a one-shot timer. Then the form setup is done and dusted by the time the service is invoked and all seems to be well.
An updated download archive is available here, which contains the original Delphi XE5 project and a Delphi XE7 equivalent, which should now be functionally equivalent.
Another update has been made to the project download, which now contains Delphi XE8 support. Delphi 10 Seattle introduces its own support for native Android services, but Delphi XE8 / Lollipop made some changes that broke the demo as it was originally written. The XE8 version of the project should hopefully resolve that problem.
Wednesday, 10 September 2014
Delphi and NFC on Android
If you’ve got an NFC sensor on your phone or tablet then there is a reasonable chance you’ve played around with apps like Trigger, which perform various actions on your device when you wave it over NFC tags in stickers or on key fobs etc. after a bit of setup.
So, for example, you could have an NFC sticker by the front door that has been coded by Trigger to turn off Wi-Fi and Bluetooth. With a variety of of NFC tags around and about you can set up your phone how you need it when you need it by a simple wave, avoiding a whole lot of fiddling about in the device settings.
Anyway, that’s one application of NFC tags. There are, of course, plenty more.
Indeed there have been a good number of questions in various forums asking how to get programmable NFC support in Delphi. Of course NFC is not currently “wrapped up” by Delphi’s RTL so up until now it’s been in the hands of the “creative”.
NFC tag scanning support in Android falls into 2 areas:
- You install an app that advertises that it can respond to some NFC tag content. When the device is waved against such a tag the app can be automatically launched. If more than 1 app is registered Android will initially launch a chooser dialog to allow the user to pick the app they require.
Actually this support is easy enough to do in Delphi so long as you can locate a suitable import unit or two containing the required Android APIs for NFC. - You run an app that permits the user to scan NFC tags while it is in the foreground and it directly responds to any scanned tags.
This seems to be more commonly required in commercial applications and alas is much more difficult to achieve with Delphi. It falls into the category of problem that requires some Java smarts and some command prompt hackery to achieve.
Bummer.
Anyway, I was recently looking into writing some NFC support, given the frequency of questions being asked. Part way through my research I discovered that Daniel Magin was simultaneously trying to do the same thing, primarily for a talk at Delphi Tage.
I helped Daniel out with the Java callback and command-line building trickery – that seems to be an area where I can readily add value to Android low level chicanery – and he helped me out overcoming a nasty crash bug with Java arrays of NFC data records not being surfaced correctly by the Delphi RTL.
In the end we both had some sample apps that permit NFC scanning and also, just as an added bonus, NFC writing!
You can find my solutions written up in quite some detail here:
- NFC support in Delphi XE5
- NFC support in Delphi XE6
- NFC support in Delphi XE7 and XE8
- NFC support in Delphi 10 Seattle and Delphi 10.1 Berlin
Daniel’s efforts will also be made available very soon.
Enjoy coding up your NFC apps, everyone!
Update - Dec '15
A number of people had tried to use the code on versions of Android more recent than was current when I worked all this and hit problems with the code crashing. This was down to some inappropriate use of JNI constructs where the problem didn't originally show up but did show up as later versions of Android got more picky about things. I've remedied this issue in 2 ways.
1) I've updated the samples and code snippet in the article (it's OnNewIntentNative that has changed, FYI, in its usage of the intent JNI value).
2) However I've also devised a different sample app (for XE7, XE8 and 10 Seattle) that does much the same thing but doesn't really use explicit JNI. Instead it uses a listener interface implemented in Delphi and called from Java. The app has been slightly extended to allow the NFC support to be toggle on and off via a checkbox.
Updated samples:
Update – Sep ‘16
While catching up on what’s new in recent releases of Delphi I realised a change had been snuck into Delphi 10 Seattle that makes the whole NFC exercise much more straightforward now in Delphi. No more Java required! No more activity subclassing! No more debugging challenges!
It turns out that the key activity callback that NFC foreground dispatch relies upon (Activity.onNewIntent) is now hookable from Delphi code (with the right know-how) and so all the Java shenanigans can be put behind us (at least in the context of NFC access).
I have updated the article to show the more direct means of accessing NFC from Delphi 10 Seattle and later and provided corresponding updated samples for Delphi 10 Seattle and Delphi 10.1 Berlin.
Wednesday, 7 May 2014
Launching other activities from Delphi Android apps
Following on from my recent post about adding Android app splash screens in Delphi XE5 and Delphi XE6 I’ve now spent some time writing up details on how to launch various Android system activities. This includes the more interesting business of getting feedback from launched activities; a common use case here is using a barcode scanner and finding what barcode what scanned.
Again there are two articles, one for Delphi XE5 and one for Delphi XE6. The XE5 version is much longer as it involves documenting a whole bunch of command-line shenanigans (much like for the splash screen) to hook the activity results. This is made much easier in Delphi XE6, thankfully.
I’ve tried to do a thorough coverage of the subject matter, highlighting any issues I bumped into – I hope it is of use to anyone tinkering with Android apps in Delphi.
Wednesday, 23 April 2014
Splash screens in Delphi Android apps
I’ve been meaning to do it for quite a while and I recently started writing up my steps for creating an Android splash screen (as per my CodeRage 8 session). No sooner did I do so that Delphi XE6 launched itself onto the scene, making my write up immediately slightly out of date :-/
Unperturbed, I finished the job off and if you’re interested you can read it here. Hopefully that makes things clearer than the breakneck pace of the video….
I also then did the necessary updates for Delphi 6, taking account of the small changes that I’ve seen in this area. You can read the Delphi XE6 version here.
I’ll hopefully get some more words written onto the Web soon, regarding other Android features not wrapped up by Delphi’s Android FMX implementation, as per some of the other demos from the CodeRage session.
Tuesday, 31 December 2013
Catching up on happenings in the Delphi world
When I’m head-down in a ‘long hours’ contract I tend to miss quite a bit of Delphi-oriented news. Once in a while I look up and I find a whole host of interesting posts around the blog-world and this has been the case over this seasonal break.
I’ve been browsing around seeing what’s new and have collated the following list of stuff I found interesting. Anyone else who hasn’t been keeping up-to-date on news of late might possibly also find some stuff of interest in the list.
Happy New Year!
Monday, 25 November 2013
Delphi and Android services (part 2)
It’s been a while now since I posted up the link to my Delphi service example on Google Play.
I mentioned at the time that it was not a trivial exercise and was somewhat imperfect in implementation (although I’d done my best to disguise this fact). Indeed you only really see an issue if you are looking at the logcat output from the app (either using the command-line adb logcat command, or using the deprecated DDMS tool or the replacement Monitor tool). Alas the app dies while endeavouring to tidy up for exit…
I also mentioned at the time that I was hoping to work out some scheme to remedy the situation before releasing the example source, something to do with pride or perfectionism or some such… Anyway, with the day job, the evening job, the prep work for last week’s Be-Delphi 3.0 event in Belgium my plans haven’t been accomplished and I have still to work out if it’s feasible to clean up the shutdown part of the sample. All my current efforts have come to little in resolving it.
So, given that there have been a number of requests for the source I have now made it available at this download link. This is the same as the sample online other than it has no splash screen. This example is free of a splash screen to simplify the example and leave it clearer. There are a couple of examples that incorporate a splash screen and have similar custom build steps available in my CodeRage 8 session files.
Please note that the archive has a Readme file in it, and you should take the time to read through this file carefully as it explains the non-standard build steps required to get the sample successfully built for deployment. If you don’t follow the Readme file, then you’re unlikely to get any joy with the sample at all.
For your convenience I include the text of the ReadMe file below.
As you will see, since Delphi has no catering for building Delphi services or broadcast receivers, I’ve had to go “round the houses” to do it, using Java stubs, and pertinent thread-switching between the Java and Delphi threads.
As you will also perhaps appreciate, I don’t recommend this as a productive way of building an Android service. However if you need to add a service to a Delphi Android application, then this approach allows you to do so.
But… as of the time of posting there is a still the small matter of a (slightly brushed under the carpet) death-by-tombstoning bug on shutdown. If any keen reader can work out a clean way of closing I’d be most obliged to hear of it!
[Update]
When the small Java source files get compiled, the Android dx tool expects them to be compiled by the JDK 1.6.x compiler as opposed to the JDK 1.7.x compiler. If you have JDK 1.7.x installed, you hit a problem with dx reporting:
bad class file magic (cafebabe) or version (0033.0000)
However, to avoid forcing a reinstall of JDK 1.6 you might like to modify my build.bat batch files and add in extra command line switches to the javac.exe command-lines. You need to insert this after the javac.exe command to force Java 1.6 byte code output, which is digestible by the Android dx command:
-source 1.6 -target 1.6
[Update 2 – Feb ‘15]
There has been a longstanding issue with my service sample, which I originally wrote for Delphi XE5.
The issue was that when updated and tested in Delphi XE7, it hung on startup with a black screen. This was rather disappointing.
Unfortunately I’ve been very much tied up with stuff and haven’t managed to get to looking into the problem up until now. Anyway, Aleksey N’s comment (below) put me onto the way of getting it to work. The OnCreate handler now triggers a timer to start the service, after the initialisation process.
The download sample project now incudes both a Delphi XE5 and a Delphi XE7 project. Enjoy!
Service example
===============
This project implements an Android service along with a couple
of broadcast receivers to catch and respond to intent messages
flung around the system. The service and receiver classes are
implemented as extremely shallow Java classes, which need to be
compiled and converted to an appropriate executable format
(dex), and then merged into the other dex code deployed with an
Android app.
The Java code calls into native Delphi code to implement
the "business end" of the service and receivers.
Build the Java support files:
----------------------------
In the project's java directory are some source files:
- java\src\com\blong\test\ActivityReceiver.java
- java\src\com\blong\test\SampleService.java
- java\src\com\blong\test\ServiceReceiver.java
These need to be compiled to .class files, archived into a .jar
file, converted from Java byte code to DEX (Dalvik Executable)
format and merged into the normally used (by Delphi's Android
deployment process) classes.dex.
To set this up, follow these steps:
- Ensure the useful subdirectory of Android SDK's build-tools
directory is on the system PATH (e.g. C:\Android\android-sdk-
windows\build-tools\18.0.1 or C:\Users\Public\Documents\RAD
Studio\12.0\PlatformSDKs\adt-bundle-windows-x86-20130522
\sdk\android-4.2.2)
- Ensure the Java Development Kit's bin directory is on the
system PATH (e.g. C:\Program Files (x86)\Java\jdk1.6.0_23\bin)
- Run a command prompt in the project's java subdirectory and
ensure you can successfully launch each of these:
- javac
- jar
- dx
- Review the build.bat file and ensure the environment
variables are set correctly:
- ANDROID needs to point to your Android SDK base
directory, e.g. C:\Users\Public\Documents\RAD Studio\12.0
\PlatformSDKs\adt-bundle-windows-x86-20130522\sdk or
C:\Android\android-sdk-windows
- ANDROID_PLATFORM needs to point at an installed SDK
platform installation, e.g. %ANDROID%\platforms\android-15 or %
ANDROID%\platforms\android-17. Check for one that is installed.
- DX_LIB needs to point to the lib subdirectory under the
Android SDK build-tools directory, e.g. %ANDROID%\build-
tools\18.0.1\lib or %ANDROID%\build-tools\android-4.2.2\lib
- EMBO_DEX needs to point to the Delphi-supplied Android
classes.dex file, wrapped in quotes to take care of any spaces
in the path, e.g. "C:\Program Files (x86)\Embarcadero\RAD
Studio\12.0\lib\android\debug\classes.dex"
- Run build.bat
- You should now have a new file in the project directory tree
called java\output\dex\classes.dex
This file replaces the supplied classes.dex and has the Java
service and broadcast receiver compiled classes included in it.
Set the new classes.dex for deployment:
--------------------------------------
Open the project in the IDE
Choose Project | Deployment
Note that the classes.dex file from the project's
java\output\dex directory is set to be deployed.
You must ensure that the default classes.dex file is de-
selected. As you switch configurations, this de-selection will
be lost (the file will be re-set to be deployed) and will need
to again be de-selected. This is an IDE bug with Delphi XE5 RTM
and XE5 UP1 and is logged in Quality Central as bug 118472.
Register the service:
--------------------
This has already been done for this demo. It involves the
following:
- Open the Android manifest template,
AndroidManifest.template.xml, which is generated on first
compile, from the project directory
- Add in a description of the service in the application
element:
<service android:name="com.blong.test.SampleService" />
Build the Delphi Android application library:
--------------------------------------------
In the IDE choose Project | Compile ServiceApp (or press
Ctrl+F9)
Deploy the library to an Android application package (.apk):
-----------------------------------------------------------
In the IDE choose Project | Deploy libServiceApp.so
Install the app on the device:
-----------------------------
In the IDE choose Run | Run Without Debugging (or press
Ctrl+Shift+F9).
This will implicitly do the compile and deploy steps above, so
they are actually optional.
This step will uninstall the app if already installed and then
install the newly built version.
Tuesday, 12 November 2013
CodeRage 8 video replays are up
For anyone that’s been waiting for the replay videos from CodeRage to go up and has been getting impatient as the suggested 2 week window has come and gone, relief is now available as the replay videos are all there.
You can find them on YouTube on the Embarcadero TechNet page, or on the original CodeRage 8 session page.
Well, ok, maybe as I type one or two are still slowly dribbling onto the Internet and maybe the sessions page hasn’t quite got all the video links on board, but the majority are accessible in one way or another on YouTube at last.
I’ve updated my CodeRage 8 session files post to include the video links to my talks in case anyone wants to check them out. Enjoy!
Wednesday, 6 November 2013
Delphi and Android services
Since Delphi’s introduction of Android support with the release of XE5, there have been many questions posted hither and thither regarding whether and how you can build service applications with it. The pervading suggestion or suspicion is that maybe Delphi isn’t cut out to build such exotic Android creations.
Well, if your goal is to just build some sort of a service app I wouldn’t particularly recommend Delphi for the job right now, simply because it hasn’t got the wherewithal to support you in that endeavour in its current guise, and consequently it’s quite difficult. Really, if you just want to build a service app you’d probably have an easier time using Java or Oxygene for Java in conjunction with the Android SDK.
However if you are invested in building a Delphi Android app, are in the midst of building a FireMonkey application for mobile deployment, and need an Android service as part of that, well it’s quite possible. But as I may have mentioned, it’s neither particularly easy nor especially straightforward.
I am aware that I have (at this time of writing) yet to write up the business of adding Android menus to Delphi apps, employing a splash screen and launching Android activities and getting results back (as demo’d in my CodeRage 8 talk, albeit with code samples available in that linked post)*.
Now I can add to the list of things I have yet to write up the steps for creating a service application. If you take a look at this Google Play Store listing you’ll see I’ve built an app that, as well as a splash screen, also implements a service.
So yes, it’s quite feasible to build a service and a broadcast receiver in a Delphi app. That said, I’ve had to be a little creative on exiting the app to avoid a failure being evident on the screen.
As mentioned, these Android aspects that fall outside the standard simple business app paradigm haven’t factored into what is readily supported currently in Delphi’s Android support. Hopefully this will be improved as time goes on to allow all sorts of Android features and facets to be surfaced in Delphi Android code. In the mean time a certain degree of spelunking and skulduggery is needed to achieve certain ends.
I know quite a few people are clamouring for knowledge on how to build service apps. Hopefully in the near future I’ll write it up, but certainly in the nearer future I’ll release the code sample, once I’ve exhausted possibilities to clean up the wrinkle around app shutdown. That should satisfy the keener of you out there. In the mean time, be satisfied that it’s been proved to be possible at all.
Thursday, 17 October 2013
My CodeRage session files
I’ve got two session this year, both related to Delphi mobile development, and both concerning how to reach out from the island that is the FM Application Framework (aka FMX aka FireMonkey) and gain access to the underlying mobile OS platform APIs.
The first session is Accessing the iOS API and looks at how Delphi-written iOS apps can talk to the CocoaTouch APIs and access additional iOS frameworks. We look at the Objective-C bridge and see how it is used to import iOS APIs, namely classes and protocols (Apple’s term for what we call interfaces), and how you can implement iOS interfaces and inherit from iOS classes. We also briefly look at how to pull in APIs that are not already imported by Delphi’s RTL. As a proof of concept we briefly see a Delphi iOS app that has no FMX code or units in it whatsoever, operating purely through the iOS APIs using the standard CocoaTouch model.
Files from the Accessing the iOS API session can be downloaded from here.
The second session is Accessing the Android API and looks at how Delphi-written Android apps can talk to the Android SDK classes. We look at the Java bridge and see how it is used to import Android APIs. We’ll also look at how to pull in APIs that are not already imported by Delphi’s RTL. We also look at how to add a splash screen to an Android app to cover up the startup time on anything other than the fastest devices, how to add Android menus to an app and how to launch external activities and get results back from them.
Files from the Accessing the Android API session can be downloaded from here. Take note that since several of the samples involve various required preliminary steps in order to function, as they step outside the comfort zone of Delphi XE5 RTM’s Android support, you should check the ReadMe.txt files supplied in the project directories of those projects.
[Update]
I plan to write up some of the subjects covered by these demos in further posts or articles as time and work schedules permit. However in the mean time I’ll respond to comments by expanding this post as necessary.
It appears that when the small Java source files get compiled, the Android dx tool expects them to be compiled by the JDK 1.6.x compiler as opposed to the JDK 1.7.x compiler. If you have JDK 1.7.x installed, you hit a problem with dx reporting:
bad class file magic (cafebabe) or version (0033.0000)
However, to avoid forcing a reinstall of JDK 1.6 you might like to modify my build.bat batch files and add in extra command line switches to the javac.exe command-lines. You need to insert this after the javac.exe command to force Java 1.6 byte code output, which is digestible by the Android dx command:
-source 1.6 -target 1.6[Update 2]
Current write-ups:
- Splash screens are written up here for Delphi XE5 and Delphi XE6.
- Launching activities and getting results back is written up here for Delphi XE5 and Delphi XE6.
Friday, 20 September 2013
Android resources
For those Pascal programmers looking at building Android applications, be it with Delphi XE5 or with Oxygene for Java (I work with both!), here are a few Android-related resources that may come in useful:
- Google’s Android Device Manager – if you mislay your Android device this allows you to locate it on a map (if it’s got a data/WiFi connection) and also ring it (presumably if it’s a telephone – I haven’t checked whether this option does anything on a tablet). Clearly this is similar to Apple’s Find My iPhone functionality.
[Update: Jim confirms that tablets will happily ring too] - Using remote Android emulators – because Android emulators emulate the device CPU they can be hideously slow, and basically unusable in a VM. If your dev tool runs in a VM then it can be useful to communicate to an Android emulator (technically called an Android Virtual Device or AVD) either on the host machine or another machine on your network. This is a useful technique entirely independent of your chosen development tool as it revolves around how your local adb.exe communicates with the emulator. This post by Jim McKeeth runs through how to set this up using SSH. You can also find a write-up in the Delphi online documentation.
- If you are using Oxygene for your Android development you may want to look at setting up your AVD to use an x86 CPU, potentially taking advantage of Intel Virtualization Technology via Intel HAXM (Hardware Accelerated Execution Manager) to provide VM acceleration. Delphi developers cannot take advantage of this because Delphi targets the ARMv7 CPU.
- App testing across many devices. The Android emulator has long been held up as pretty much the only way of testing your app across the range of form factors that different devices can offer. Now it’s not the only option though, as Apkudo for Developers offers developers a free online app-testing platform where your app will be tested on over 260 different Android devices. Just upload your app to the queue and a report will be sent back when the tests have been run.
- Since Android’s Ice Cream Sandwich release introduced the Roboto font as the default, you may want a copy to install on your machines. You can download it from the link in the blue box here (or this is the direct d/l link).
- Google’s sample icons pack can be downloaded with this link.
- For anyone who does presenting it can be very useful to have a means of showing on your computer screen what your device is doing. There are various VNC-based solutions for this out there, but Jim McKeeth has built a simple solution using repeated screen-captures called Android Screen View. You can download the source code for it here or pull down a build here.
- The Android dashboards show you the percentage of devices sharing various characteristics as obtained from the Google Play store. All the devices in question will be running Android 2.2 (FroYo) and above.
This device breakdown can be useful to decide what OS and form factor to ensure you support.
On the dashboards you can see the breakdown of:- Android OS versions
- Screen sizes and densities
- OpenGL version
- If you have a nose that needs to be poked inside everything, consider pulling down the Android source code. Information on how is available here.