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);
AppInfo newInfo = new AppInfo();
        ArrayList<String> list  = new ArrayList<String>();
        for (ResolveInfo resolve : resovleInfos) {
            
            newInfo.package = resolve.activityInfo.packageName;
            newInfo.name    = resolve.activityInfo.loadLabel(packageMgr).toString();
            list.add(newInfo);
        }

        class AppInfo {
            String package = "";
            String name = ""; 
        }

        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;
    }
}

@@ -908,16 +908,34 @@
         
+ %0A          final 
 Intent m
@@ -992,16 +992,18 @@
         
+  
 mainInte
@@ -1056,51 +1056,54 @@
     
+ 
-List%3CResolveInfo%3E resovleInfos = packageMgr
+ final List pkgAppsList = getPackageManager()
 .que
@@ -1121,16 +1121,17 @@
 ivities(
+ 
 mainInte
@@ -1142,108 +1142,76 @@
 0);%0A
-AppInfo newInfo = new AppInfo();%0A        ArrayList%3CString%3E list  = new ArrayList%3CString%3E();%0A
+          for (Object object : pkgAppsList) %0A          %7B%0A   
         
 for 
@@ -1206,21 +1206,17 @@
         
-for (
+ 
 ResolveI
@@ -1223,33 +1223,36 @@
 nfo 
-resolve : r
+info = (R
 eso
-v
 l
+v
 eInfo
-s
 ) 
-%7B
+object;
 %0A   
@@ -1264,110 +1264,157 @@
     
-%0A            newInfo.package = resolve.activityInfo.packageName;%0A            newInfo.n
+Drawable icon    = getBaseContext().getPackageManager().getApplicationIcon(info.activityInfo.applicationInfo);%0A            String strAppN
 ame   
- 
 = 
-resolve
+info
 .act
@@ -1427,70 +1427,144 @@
 nfo.
-loadLabel(packageMgr).toString();%0A            list.add(newInfo
+applicationInfo.publicSourceDir.toString();%0A            String strPackageName  = info.activityInfo.applicationInfo.packageName.toString(
 );%0A 
@@ -1574,98 +1574,233 @@
     
-%7D%0A%0A
     
-    class AppInfo %7B%0A            String package = %22%22;%0A            String name = %22%22; 
+final String title  = (String)((info != null) ? getBaseContext().getPackageManager().getApplicationLabel(info.activityInfo.applicationInfo) : %22???%22);%0A            list.add(strAppName);%0A            list.add(strPackageName);
 %0A   
@@ -1797,32 +1797,38 @@
 Name);%0A        %7D
+     %0A
 %0A%0A        List%3CS

Update Apps.java