Convert Cordova Custom Plugin for Win8/RT


  • I am in the midst of converting a html/javascript app that runs on iOS/Android to work on Windows 8/RT. I have most of the HTML/Javascript/jQuery working on the Windows 8/RT but need to figure out how to get the custom plugin working on windows 8.  Or how to build a wrapper that allows for the same functions. 

    That said I have a couple questions.

    1) What is the native language of Windows 8/RT?

    • In Android, my Javascript plugin talks to a JAVA file (in native Android Code) and returns a pluginresult.  What is the equivalent on Windows 8?

    2) Is there any documentation on how to setup a Windows 8 plugin?

    • The Phonegap page only currently lists Windows Phone 8/7 documentation.

    3) The Cordova plugin supports a window.openDatabase function for both iOS and Android, is there an equivalent on Windows 8?

    4) Does Windows 8 allow Bluetooth communication with a paired device?

    Friday, January 11, 2013 3:53 PM


All replies

  • What is the reason your are using the plugin?  Are the reasons related to questions 3 & 4?  I ask because if our API can already service your needs, then there is no need to introduce the plugin.

    Michael Palermo Microsoft Evangelist

    Friday, January 11, 2013 6:01 PM
  • Hi,

    First, Win8 has already provided two methods to develop. You can use c#/xaml or javascript/html5.

    If you are coding with javascript/html5. I think there is no need plugin of Win8. Because you can write some component with C#/C++. And then call that in javascript.

    #Creating Windows Runtime Components


    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 15, 2013 7:39 AM
  • The only reason for the plugin is consistency amongst the apps, and it handles callbacks asynchronously.  But since posting I have found that the APIs have worked well and I have implemented a Windows Component, which worked well.  I am in the process of using the WinJS to handle calls that the Cordova plugin would have handled and with that I have a couple questions.

    1) With the Cordova on iOS/Android I am using window.openDatabase which opens a SQLite database object in the browser.  Does MSFT recommend using the window.indexedDB, which is not SQL, or would using this component SQLite3-WinRT, be a better option?

    2)  What is the best way to handle callbacks aynchronously?  In my core code I call these functions that talk to the native code in this manner window.plugins.TCPComm.FunctionName("data to be sent", successCallback, failureCallback).  I have created a plugin and added the same functions so my calls in the main code do not change.  That said the function calls within the FunctionName need to be executed asynchronously...  I hope this makes sense..

    An example would be the following

    (function () {
    var TCPComm = function () { };
        TCPComm.prototype.Open = function (Cmd, successCallback, failureCallback) {
               wOpenSocket("IP Address", "Port") // NEEDS TO RUN ASYNCHRONOUSLY
    if (!window.plugins) {
        window.plugins = {};
    if (!window.plugins.TCPComm) {
        window.plugins.TCPComm = new TCPComm();

    3)  I have an instrument I need to connect and open a Bluetooth socket, or any form of communicative socket, so I can read/write data from it.  This can also be handled as if I was opening a COM port as well.  Does the Windows RT have support for this?  In the native android code all I do is create an object that holds an instance of the bluetooth adapter, get a list of paired devices and connect to one of the devices and then I can read/write to it.  I have been struggling to find something similar within the MSDN docs. 

       Here is a piece of my Android code that gets the adapter and returns the addresses.

    BluetoothAdapter Adapter = BluetoothAdapter.getDefaultAdapter();			 		 
    		 	Set<BluetoothDevice> pairedDevices = Adapter.getBondedDevices();
    		 	if (pairedDevices.size() > 0) {
    		 		for (BluetoothDevice Device : pairedDevices) {
    		 			Log.d("MyApp",Device.getName() + "\t" + Device.getAddress());   			

    4)  On the datagramsocket class, I need to broadcast a character array to a certain IP address and port, then expect a response back.  On looking at the DatagramSocketCllass I have been unable to find an example that lets me do that.  Any thoughts/help here?  Edit: quick note this is within javascript.. if I need to write a WinComponent I can.  

    Once again, thank you for your time and I hope everything makes sense.  Articulating these things clearly can be difficult for me sometimes.  Additionally I am in the process of learning things as well so please forgive any stupid mistakes/errors.

    EDIT #1 - Solved.  Used SQLite-WinRT and the solution works great!

    EDIT #3

       According the various MSFT responses on these forums there is no way to access the Bluetooth Stack.  My question now is there any word if this will be released in the meantime?

    EDIT #4 - 

        I was able to get number four resolved.  Thanks to the DataSocket Example

    • Edited by MTAG11 Thursday, January 17, 2013 1:40 PM
    Tuesday, January 15, 2013 2:49 PM
  • Hi,

    For Data access and storage mechanism. Please refer to my blog: http://blogs.msdn.com/b/win8devsupport/archive/2012/12/19/using-html5-javascript-in-windows-store-apps-data-access-and-storage-mechanism-i.aspx .

    And if for device info, I suggest you using component.

    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Thursday, January 24, 2013 10:21 AM
    Thursday, January 17, 2013 8:44 AM