Question

We have been working on an Android project using Adobe AIR for a long time and now we need to implement the feature to search for Upnp devices in the network. From my understanding, it is not possible to implement this feature on AIR level (please correct me if I am wrong), so an Android native extension is required. I could not find any UPNP Native Extension available and decided to build one based on Cling library Cling UPNP Browser. I could get it work as native Android application but when I tried to convert it to AIR native extension, it did not work at all. Does anyone successfully implement the UPNP on Android - AIR, any help will be greatly appreciate.

Was it helpful?

Solution

After spending more time to search for other alternative, finally, I have made it work using CyberLink For Java. The implementation of CyberLink library is very straight forward. For anyone plans to create your own UPNP Native Extension for Android, here is the process to build your .jar native extension.

  1. Include the external cyberlink .jar library to your Android Java project.
  2. To start searching for UPNP Devices, you have to open a new thread:

       new SearchingForUpnpTask().execute("Empty Param"); //You can specify your own param...
       private class SearchingForUpnpTask extends AsyncTask<String, Void, DeviceList>{
            protected DeviceList doInBackground(String... params){
                ControlPoint ctrPoint = new ControlPoint(); 
            ctrPoint.start("upnp:rootdevice");
                DeviceList devList = ctrPoint.getDeviceList();
                int nRootDevs = devList.size(); 
            for (int n=0; n < nRootDevs; n++) { 
                    Device dev = devList.getDevice(n); 
            String devName = dev.getFriendlyName(); 
                System.out.println("[" + n + "] = " + devName); 
            }
        ...              
       return devList;
      }
    
  3. To compile the .jar file for your Android will require some works as Adobe AIR does not understand your external cyberlink .jar file that we include. When you try to debug the native extension, you will receive the error Log: ...the class 'org...ControlPoint' is not found in the method ... . In order to make it work, you have to combine all the .jar files into one. We have 2 options here:

    • 1st method: Export your Andoird .jar file, change the extension to .zip then unzip it. Then change the .jar extension of the cyperlink .jar file to .zip then unzip it. Copy the source from the cyperlink .jar folder to your Android's .jar folder. Finally, jar the whole folder again.

    • 2nd method (easier): Use jarjar.jar from Google (thanks to Joe Ward).

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top