Salesforce

How Do I Execute Native Code in My Mobile Application? (Magic xpa 3.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Execute Native Code in My Mobile Application? (Magic xpa 3.x)

Sometimes you need to use native OS code in your application; for example, when using custom hardware or when you need to access information from the device, such as the contacts list.

The installation of Magic xpa includes samples of using native OS code. The image below shows you the Android folder where you can find the samples. There is a similar folder for iOS.

The available samples are detailed in the Mobile Native Code section in the Connectivity and Misc. Samples topic.

You can execute native code in your mobile app by calling from your Magic app to the native code. This can be done by evaluating the ClientNativeCodeExecute() function with the name of the native code method and parameters.

So, for example, in the image below, the ClientNativeCodeExecute() function will execute the resize method in the ImageResize class in the mobile application code and pass it the arguments of filename, ratio, width and height.

For iOS, although you are sending several different parameters to the method, you need to define the called method with only one parameter of NSArray type. All of the Magic parameters are automatically set into this array. Then you can retrieve the parameters from the array.

The native code for this function looks as follows:

Android

The ImageResize.java file located in the Rich Internet Samples\Android\ImageResize-src folder:

iOS

The AppDelegate.mm file located in the RIAModules\iOS\Source\MagicApp folder:

Windows 10 Mobile

The ImageResize.java file located in the Rich Internet Samples\Windows10Mobile\ImageResize-MagicApp folder:

See also

Reference
Attachment 
Attachment