Developer Barış Atalay has released a demo with source that implements a dynamic broadcast receiver for Android in Delphi XE6 Firemonkey (and I assume it should upgrade to XE7 easily). On Android a Broadcast Receiver is a service that listens for a broadcast to execute an action within an app (usually via an Intent). This is accomplished by creating a custom classes.dex file with three Java classes that implements a BroadcastReceiver. Within the Delphi app an OnReceive event is defined and that is where you process the received Intent from the broadcast. In the case of the source code demo it sends a toast message when an Intent is received. The Android JNI code in this project is pretty complex and but since it is a demo with source I think you can just start building your own code on top of the existing foundation. It looks like it uses a RegisterDelphiNativeMethods which is similar to the function used in this Firemonkey JNI callback example. The blog post is in Turkish so you may want to use Google Chrome to translate it. This demo should also work with Appmethod without too much trouble.
And download the demo source code for the Delphi XE6 Firemonkey broadcast receiver app here.
1 Comment