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 android.annotation.SuppressLint;
import android.content.Context;
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 packageMgr = ctx.getPackageManager();
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> resovleInfos = packageMgr.queryIntentActivities(mainIntent, 0);

        ArrayList<String> list  = new ArrayList<String>();
        for (ResolveInfo resolve : resovleInfos) {
            String packageName = resolve.activityInfo.packageName;
            list.add(packageName);
            String strAppName  = resolve.activityInfo.loadLabel(packageMgr).toString();
            list.add(strAppName);
        }
        List<String> ulist = new ArrayList<String>(new HashSet<String>(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;
    }
}

@@ -851,284 +851,422 @@
     
+List%3C
 Package
-Manager packageMgr = ctx.getPackageManager();%0A        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);%0A        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);%0A        List%3CResolveInfo%3E resovleInfos = packageMgr.queryIntentActivities(mainIntent, 0
+Info%3E apps = getPackageManager().getInstalledPackages(0)%0A%0A        %0A        ArrayList%3CAppInfo%3E res = new ArrayList%3CAppInfo%3E();%0A            for(int i=0;i%3Capps.size();i++) %7B%0A                        PackageInfo p = apps.get(i);%0A         %0A                        AppInfo newInfo = new AppInfo();%0A                        newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString(
 );%0A
-%0A
         
 Arra
@@ -1265,177 +1265,276 @@
     
-ArrayList%3CString%3E list  =
+               
  new
- ArrayList%3CString%3E();%0A        for (ResolveInfo resolve : resovleInfos) %7B%0A            String packageName = resolve.activityInfo.packageName;%0A
+Info.pname = p.packageName;%0A                        newInfo.versionName = p.versionName;%0A                        newInfo.versionCode = p.versionCode;%0A                        newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());%0A           
     
@@ -1533,32 +1533,33 @@
                 
+ 
 list.add(package
@@ -1555,20 +1555,131 @@
 add(
-packageName)
+newInfo);%0A                        %7D%0A                    %7D%0A         %0A        class AppInfo %7B%0A            String appname = %22%22
 ;%0A  
@@ -1699,120 +1699,137 @@
 ing 
-strAppN
+pn
 ame 
- 
 = 
-resolve.activityInfo.loadLabel(packageMgr).toString();%0A            list.add(strAppName);%0A        %7D
+%22%22;%0A            String versionName = %22%22;%0A            int versionCode = 0;%0A            Drawable icon;%0A         %0A        %7D%0A
 %0A   

Update Apps.java