The DataShare class is a native extension for Adobe AIR. It allows AIR application developers, from ActionScript, to use some Data Sharing features of Android and iOS.
This native extension provides options to share data through installed applications on Android and iOS mobile devices.
A sample project is attached as a zip file (under Sample files at the top of this page). The zip contains:
- The ActionScript library in the directory DataShareLibrary: This directory contains the Flash Builder project for creating the ActionScript side of the DatsShare extension.
- The Android native library in the directory DataShareAndroidLibrary: This directory contains an Eclipse project for creating Android native side of the DataShare extension. To build the eclipse project, first copy FlashRuntimeExtension.jar from <AIR_SDK>/lib/android/FlashRuntimeExtensions.jar to the directory DataShareAndroidLibrary/libs.
- The iOS native library in the directory DataShareiOSLibrary: This directory contains an Xcode project for creating the iOS native side of the DataShare extension. To build the Xcode project, first copy FlashRuntimeExtension.h from <AIR_SDK>/include/FlashRuntimeExtensions.h to the directory DataShareiOSLibrary.
- A directory called ReadyToUseExtension: This directory contains everything the AIR application developer needs to use native extension: the ANE file, the SWC file, and a text file that contains the extension ID.
- A directory called DataShareTest: This directory contains a sample AIR application that uses the DataShare native extension.
The ActionScript contains the DataShare class. The DataShare class provides the following public methods to the AIR application:
public function sendMessage(message:String = "", phoneNumber:String = ""):void
public function sendData(subject:String="",text:String="", userId:String=""):void
public function shareImage(bitmap:BitmapData,subject:String="",text:String="",userId:String=""):void
public function showToast(message:String):void
The AIR application can create many instances of the DataShare class. However, the DataShare class creates only one ExtensionContext class instance that is shared by all the DataShare instances.
To use the DataShare ANE, an AIR application does the following:
- Show Toast Message: Shows the toast message on the Android device screen by calling showToast() method, specifying the string to show as a message in the parameter.
var img_share:DataShare = new DataShare();
- Send Message: Sends the message through the built-in SMS app of the Android/iOS device by calling sendMessage() method, specifying the Phone number and the text as a message in the parameter.
var msg_share:DataShare = new DataShare();
msg_share.sendMessage(“Heyy, How are you?”, "12345678");
- Share Image: Shares the image through the pre installed aplications on the Android device by calling shareImage() method, specifying the bitmap data for the image, recipients id’s, subject, and text to show on body as a parameters. For Android, shareImage() method saves the BitmapData to the device's SD card as DataShareNativeExtImage.png and passes the path of the image to Android code (currently, it is not supported on Android M).
var email_id:String = new String();
img_share.shareImage(bitmapData,"Sharing some doc","Please find the attachment”, email_id);
- SendData: Shares text data through the pre-installed applications on the Android device by calling sendData() method, specifying the recipients id’s, subject, and text to show on body as a parameters.
var userId:String = new String();
txt_share.sendData("Your Feedback is Valuable to us","Write something here..",userId);
As the Bitmap data for the image will be first store to the sdcard as a .PNG image, include the WRITE_EXTERNAL_STORAGE permission in your application descriptor file:
The Android native library is implemented in Java, using the native extension Java API. The classes which implement FREFunction gets FREContext object as the first parameter and FREObject array as the second parameter in their call() method. The native library includes the following classes:
- DataShareExtension implements FREExtension: This class contains the createContext() method. This method is called by the AIR runtime when ExtensionContext.createExtensionContext() is invoked on the ActionScript side; it returnins a DataShareExtensionContext class instance. The initialize() and dispose() methods are called by the AIR runtime on extension initialization and destruction respectively.
- DataShareExtensionContext extends FREContext: This class contains getFunctions() method. This is an abstract method returning a Map Object functionMap that associates the extension function keys to the native FREFunction implementations.
- SendMessageFunction implements FREFunction: This class is mapped to sendMessageFunction function key in the DataShareExtensionContext class. It gets phone number and message from FREObject array and passes them to sendMessage() method as parameters. This method launches the intent Intent.ACTION_SENDTO to send message.
- ShareImageFunction implements FREFunction: This class is mapped to shareImageFunction function key in the DataShareExtensionContext class. It gets image path of the SD card, Recipient’s id, subject, and text from FREObject array and passes them to shareImage() method as parameters. This method launches the intent Intent.ACTION_SEND to share image with text data.
- ShareTextFunction implements FREFunction: This class is mapped to shareTextFunction function key in DataShareExtensionContext class. It gets the Recipient’s id, subject, and text from FREObject array and passes them to shareText() method as parameters. This method launches the intent Intent.ACTION_SEND to share the text data.
- ShowToastFunction implements FREFunction: This class is mapped to showToastFunction function key in the DataShareExtensionContext class. It gets the string from FREObject array and shows it through the Toast message.
The iOS native library is implemented in Objective C, using the native extension C API. The native library includes the following methods:
- The extension initializer and finalizer methods DataShareExtInitializer() and DataShareExtFinalizer().
- The context initializer and finalizer methods DataShareContextInitializer() and DataShareContextFinalizer().
- Native functions, using the signature of FREFunction(). The native functions are showToast(), shareText() and shareImage().
- The function shareImage() gets the Bitmap data and text to share. It creates .PNG file from Bitmap data and pass it with the subject and body text to the sharing apps.
- The function shareText() gets the text and pass it to the app through which user would like to share.
- The function showToast() gets the message and show it to the iOS device screen.
For more information about developing native extensions for Adobe AIR, see:
For more information about using a native extension in an AIR application, see: