Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiDemoFiremonkey

Implement Custom Android SDK Callback Events With Delphi XE5 Firemonkey On Android

Delphi XE6 Firemonkey Custom Android SDK EventsDeveloper Cristian Peta has a post up on the Embarcadero forum with some sample code showing how he implemented a bar code reader callback in the Android SDK for Delphi XE5 Firemonkey. Basically how Firemonkey applications work on Android is there is an Android SDK shim which is written in Java (and contained within the classes.dex file). This shim calls the actual Android NDK based Firemonkey application which is a .SO file (where your code is located). What Cristian Peta’s code does is implement some Java code and custom events in that Android SDK shim and those events make function calls into the Firemonkey application. This allowed him to implement a Honeywell SDK in Java and use it from Firemonkey. Brian Long pioneered this method in his CodeRage 8 sessions on the topic. Take a look at the BarCode and Menu demos in the AccessingTheAndroidAPI.7z download for complete examples of doing this. I am including Cristian Peta’s full post below with his implementation:

“My solution was to write some Java code then insert this code into classes.dex
Then I use this Java code from Delphi trough Java generic import and JNI.
You can read Brian Long blog about classes.dex

My starting point from Honeywell SDK examples was DecodeSampleActivity. There is that I modified and merged into classes.dex
I extended com.embarcadero.firemonkey.FMXNativeActivity but I think now it should be enough to extend Activity. When you extend Activity you do not need to decompile classes.dex

The main Delphi part is here:”


“And Java code:”


One more thing (Java generic import):


Best Regards,
Cristian Peta

For implementing existing third party SDKs like MoPub, TapJoy, Millennial Media, Google Play Services, Flurry, Chartboost, Upsight, or even new Bluetooth functionality for Android in Delphi XE5, Delphi XE6, and AppMethod this may be the fastest way.

Head over and download the samples from Brian Long on customizing your Firemonkey classes.dex file.


Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes


Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores


DelphiCon 2020 FireMonkey Sessions Available Starting November 19


Powerful Commercial Gorilla3D Framework Upgraded For Delphi FireMonkey On Windows And Android

Sign up for our Newsletter and
stay informed

Leave a Reply