Building Mobile Enterprise Applications : webMethods Mobile Development Help : Code Snippets : Using a Java Class to Communicate with the Natively Injected Code
Using a Java Class to Communicate with the Natively Injected Code
With Mobile Designer, it is possible to extend the given capabilities, especially those for interacting with the target operation system. This feature can be used to add platform-specific features to a Mobile Project, such as integrating a barcode scanner or displaying PDF files. Adding platform-specific code to a Mobile Project is called "native code injection".
The principle behind native code injection is to use a Java class as a bridge to the native code. The Java class provides a signature and with that an entry point for communicating with the native code. Furthermore, the Java class is replaced during the build process. Because of this, the native equivalent must also implement the signature to avoid any compile issues that may occur during the build process. For technical examples, see the Mobile Designer sample projects NativeUI My Native Element and the NativeUI PDF Demo.
To implement native code injection, proceed as follows:
1. Create a Java class with a common signature (for example, a static method).
2. Do a local build for the desired native platform.
3. Configure the Mobile Project to use native code injection. To do so, implement the project.hookpoint.target.postcrosscompiler hookpoint in your defaults.xml file and configure which classes need to be replaced. For more information about hookpoints, see Using webMethods Mobile Designer.
With Mobile Development, the project.hookpoint.target.postcrosscompiler hookpoint is already pre-configured in each Mobile Project. You only need to add the native classes to the project_name/native/platform folder and ensure that the folder structure matches the Java package. The platform folders are:
Platform
Folder
Android
project_name/native/android
iOS
project_name/native/ios
Phoney
project_name/native/phoney
Windows
project_name/native/winphone
For example, when you have a Java class named com.softwareag.mobile.Helper.java, you have to add the native source code for Android to project_name/native/android/com/softwareag/mobile/Helper.java.
4. The local build (see above) cross-compiles the Java class to the target platform, which results in a native source file already translated to the target programming language. You can copy this source file and customize it without having to take care of how to add imports or method declarations in the target programming language.
5. Do a build for the platform once more. The result will contain the natively injected code.
Copyright © 2007-2017 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback