WifiTags: An Adobe AIR Native Extension for getting available WiFi networks in Windows and Android Environments

April 6, 2015 by

1. Introduction

Adobe AIR is by design cross-platform and device-independent, but AIR applications can still access the capabilities and APIs of native platforms through AIR native extensions. A native code implementation provides access to device-specific features, enabling you to use platform-specific features, reuse existing native libraries, and achieve native-level speed for performance-sensitive code. These device-specific features are not available in the built-in ActionScript classes, and are not possible to implement in application-specific ActionScript classes. The native code implementation can provide such functionality because it has access to device-specific hardware and software.

In this article we present the implementation of such a native extension (WifiTags) for getting the available Wi-Fi networks (SSIDs) and their signal strength (RSSIs). Initially, we provide a brief description on the architecture of a native extension, we continue describing the implementation of the WifiTags extension, give an example for its usage and we conclude providing a real application scenario for its usage.

2. Adobe AIR native extension architecture

Figure 1 shows the interactions between the native extension, the AIR runtime, and the device [1].

AIR allows an extension to do the following [1]:

  • Call functions implemented in native code from ActionScript.
  • Share data between ActionScript and the native code.
  • Dispatch events from the native code to ActionScript.

When you create a native extension, you provide the following [1]:

  • ActionScript extension classes that you define. These ActionScript classes use the built-in ActionScript APIs that allow access to and data exchange with native code.
  • A native code implementation. The native code uses native code APIs that allow access to and data exchange with your ActionScript extension classes.
  • Resources, such as images, that the ActionScript extension class or the native code uses.

Your native extension can target multiple platforms. When it does, you can provide a different set of ActionScript extension classes and a different native code implementation for each target platform. [1]

Figure 1: Adobe AIR native extension architecture

Figure 1: Adobe AIR native extension architecture

3. Developing the native extension

The complete source for the WifiTags Adobe AIR native extension is available at [2], while the final built of the extension which can be used directly in Flash Builder is available at [3].

The extension consists of three parts:

  • The native windows library (WifiTagsWin).
  • The native android library (WifiTagsAndroid).
  • The ActionScript library (WifiTagsANE).

3.1. Windows native code

The native windows library is a C++ Microsoft Visual Studio 2013 project. The main functionality is implemented in the file WlanGetAvailableNetworkList.cpp and it is an adaptation of Microsoft Windows’ WlanGetAvailableNetworkList native Wifi function [4]. The interface to the ActionScript code is implemented in the file WifiTags.cpp and it provides two functions:

  • FREObject isSupported(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
    Which returns true as this extension is supported in windows platforms
  • FREObject getWifiTags(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
    Which returns a list of available Wi-Fi networks serialized in JSON format. A typical format of the return value is as follows:
    {"ssids":[
         {"name":"ssid1", "strength":-50, "connected":true},
         {"name":"ssid2", "strength":-51, "connected":false},
         {"name":"ssid3", "strength":-57, "connected":false}
    ]}
    

    where for each network it is provided its name (SSID), its strength (RSSI) and its connected/disconnected status.

The project also include the linker’s library FlashRuntimeExtensions.lib and the related header FlashRuntimeExtensions.h as provided by Adobo AIR SDK 16.0.

3.2. Android native code

The native android library is a java based eclipse project. The interface to the ActionScript code is implemented in the file WifiTags.java, the FREContext is implemented in WifiTagsContext.java and it also provides two function which are implemented as separate classes:

  • SupportedFunction.java which provides the isSupported function and which again returns true as this extension is supported in windows platforms.
  • WifiTagsFunction.java which provides the getWifiTags functions and which again returns the list of available Wi-Fi networks serialized in JSON format.

3.3. ActionScript library code

The ActionScript library is and Adobe Flash Builder 4.6 projects which contains the WifiTags.as file which acts as a proxy to the native parts of the code. One thing worth mentioning is that the function getWifiTags deserializes the JSON passed from the native code and passes it to the caller as an ActionScript Object.

4. Using the native extension

Having the extension’s ane file [3], you can easily add it in a Flash Builder’s project as described at [5]. A typical code that uses the WifiTags extension is the following

import gr.ictpro.jsalatas.ane.wifitags.WifiTags;

protected function getAvailableWifis():void
{
     var wifiTags:WifiTags = new WifiTags();
     if(wifiTags.isSupported()) {
          var obj:Object = wifiTags.getWifiTags();
          var numberOfNetworks:int = obj["ssids"].length;
          for (var i:int = 0; i < numberOfNetworks; i++) {
               trace("SSID:" + obj["ssids"][i]["name"]);
               trace("RSSI:" + obj["ssids"][i]["strength"]);
               trace("Connected:" + obj["ssids"][i]["connected"]);
          }
     }
}

Notice that in order to use it in an Android device, you need the ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE permissions.

5. Conclusion

In this article we presented the WifiTags native extension which provides the ability to get a list of available Wi-Fi networks in an Adobe AIR application which runs in a Windows or Android environment. The extension is tested in Windows 8.1 and Android 5.0 (Galaxy Note 3) environments and it should work on any PC running Windows 7/8.x and any Android device running at least Android 4.3.

This extension was created in order to be able to use the available Wi-Fi networks as location tags and to enable us to implement the location awareness features required in the Mobile Based Foreign Language Learning environment as described in our previous article [6].

6. References

[1] Adobe. 2015. Developing Native Extensions for ADOBE AIR. Retrieved April 5, 2015.

[2] WifiTags source code. Retrieved April 5, 2015.

[3] WifiTags: An Adobe AIR Native Extension for getting available WiFi networks in Windows and Android Environments. Retrieved April 5, 2015.

[4] WlanGetAvailableNetworkList function. Retrieved April 5, 2015.

[5] Adobe Flash Builder 4.7 – Use native extensions. Retrieved April 5, 2015.

[6] Salatas, J. 2015. Mobile based environment for foreign language learning: Use cases and sequence diagrams. Retrieved April 5, 2015.