package so.doo.app.plugins;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.annotation.SuppressLint;
import android.content.Context;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.pm.PackageInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;

import java.util.List;
import java.util.ArrayList;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

@SuppressLint("HandlerLeak")
public class Apps extends CordovaPlugin {
    
    private Context ctx;

     public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);
        ctx = cordova.getActivity().getApplicationContext();
    }

    private JSONArray list() { 
        
        PackageManager pm = this.cordova.getActivity().getPackageManager();
        List<ApplicationInfo> packages = pm.getInstalledApplications(0);
        ArrayList<JSONObject> list = new ArrayList<JSONObject>();

            for (ApplicationInfo packageInfo : packages) {
                try {
                    JSONObject json = new JSONObject();
                    json.put( "name", pm.getApplicationLabel( pm.getApplicationInfo( packageInfo.packageName, 0 )).toString() );
                    list.add( json );
                } catch (NameNotFoundException e) {}
            }

        JSONArray ulist = new JSONArray(list);
        
        return new JSONArray(ulist);
    }

    /**
     * Executes the request and returns PluginResult.
     *
     * @param action            The action to execute.
     * @param args              JSONArry of arguments for the plugin.
     * @param callbackContext   The callback id used when calling back into JavaScript.
     * @return                  True if the action was valid, false otherwise.
     * @throws JSONException 
     */
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        // list
        if (action.equals("list")) {
            JSONArray json = list();
            callbackContext.success(json.toString());
            
            return true;
        }

        return false;
    }
}

@@ -1484,18 +1484,16 @@
  %0A      
-  
 PackageM
@@ -1560,16 +1560,20 @@
         
+    
 List%3CApp
@@ -1629,12 +1629,45 @@
 ons(
-0);%0A
+ PackageManager.GET_PROVIDERS );%0A    
     
@@ -1692,20 +1692,19 @@
 Object%3E 
-list
+res
  = new A
@@ -1861,24 +1861,92 @@
 ONObject();%0A
+                    json.put( %22package%22, packageInfo.packageName );%0A
             
@@ -2082,20 +2082,19 @@
         
-list
+res
 .add( js
@@ -2155,22 +2155,8 @@
 ) %7B%7D
-%0A            %7D
 %0A%0A  
@@ -2193,20 +2193,19 @@
 ONArray(
-list
+res
 );%0A     

Update Apps.java