Testing the Plug-in

Test the PhoneGap plug-in for the Android Hybrid Web Container.

  1. Create a new Mobile Application project:
    1. Select File > New > Mobile Application Project.
    2. In Project name, enter PhonegapTest.
    3. Click Finish.
  2. Right-click the PhonegapTest project folder and select NewHybrid App Designer.
  3. Click Next.
  4. Select Can be started on demand from the client and click Finish.
  5. Click Screen Design.
  6. Add a Menu Item control to the Menu, and in the General properties, enter "c" for the menu item name.

    This is the key name you will use in the custom.js file for the customAfterMenuItemClick () function.

  7. Run the Hybrid App Generation wizard to create the directory structure Generated Hybrid App\PhonegapTest\ html\js.
  8. Open the custom.js file for editing and add this code:
    var dirlist = {
    	    getlist: function(successCallback, errorCallback) {
    	        PhoneGap.exec(successCallback, errorCallback, 'DirectoryListPlugin', 'list',["/mnt/sdcard"]);
    	    }
    	};
    
    function getDlist() {
    	dirlist.getlist(function(r) {
    		var theHtml = "";
    		if(r.children)
    		{
    			var index = 0;
    			for(index = 0; index <= r.children.length;index++)
    			{
    				if(r.children[index]){
    					theHtml += r.children[index].filename + " \n ";
    				}
    			}
    		}
    		else
    		{
    			alert("No r.children!!");
    		}
    		alert(theHtml);
            },
            function(error) {
                alert('Error:' + error);
            }); 
    }
    
  9. Add this code in the customAfterMenuItemClick () function:
    if(menuItem == "c"){
    		getDlist();
    	}
  10. Regenerate the Hybrid App.
  11. Assign the Hybrid App to a device that has the Hybrid Web Container with the custom plug-in.
  12. On the device, run the Hybrid App, click Menu, and click c.
    The <custom_plug-in>.java file appears on the SD card in the list of files.