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;
            Bundle strAppName  = resolve.activityInfo.metaData;
            list.add(packageName);
            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;
    }
}

@@ -843,69 +843,8 @@
 ) %7B%0A
-        PackageManager packageMgr = ctx.getPackageManager();%0A
     
@@ -854,21 +854,21 @@
  Intent 
-mainI
+homei
 ntent = 
@@ -900,14 +900,8 @@
 MAIN
-, null
 );%0A 
@@ -907,21 +907,21 @@
         
-mainI
+homei
 ntent.ad
@@ -950,16 +950,12 @@
 ORY_
-LAUNCHER
+HOME
 );%0A 
@@ -965,149 +965,193 @@
     
-List%3CResolveInfo%3E resovleInfos = packageMgr.que
+homeintent.addCatego
 ry
+(
 Intent
-Activities(mainIntent, 0);%0A%0A        ArrayList%3CString%3E list  = new ArrayList%3CString%3E();
+.CATEGORY_DEFAULT);// seems not needed here since This is a synonym for%0A        // including%0A        // the CATEGORY_DEFAULT in your supplied Intent per doc
 %0A   
@@ -1159,14 +1159,14 @@
     
-for (R
+this.r
 esol
@@ -1176,64 +1176,110 @@
 nfo 
+= pm.
 resolve
- : resovleInfos) %7B%0A            String packageName
+Activity(homeintent, PackageManager.MATCH_DEFAULT_ONLY);%0A        ActivityInfo activityInfo
  = r
@@ -1276,32 +1276,36 @@
 tyInfo = resolve
+Info
 .activityInfo.pa
@@ -1305,63 +1305,44 @@
 Info
-.packageName;%0A            Bundle strAppNam
+;%0A        userHomeLauncherPackag
 e 
- 
 = 
-resolve.
 acti
@@ -1354,39 +1354,8 @@
 nfo.
-metaData;%0A            list.add(
 pack
@@ -1357,25 +1357,24 @@
 .packageName
-)
 ;%0A          
@@ -1375,32 +1375,49 @@
     
-    list.add(strAppN
+userHomeLauncherClass = activityInfo.n
 ame
-)
 ;%0A  
@@ -1426,106 +1426,70 @@
     
-%7D%0A        List%3CString%3E ulist = new ArrayList%3CString%3E(new HashSet%3CString%3E(list));%0A        %0A        
+userHomeLauncherName = activityInfo.loadLabel(pm).toString();%0A
 retu
@@ -1506,20 +1506,35 @@
 NArray(u
-list
+serHomeLauncherName
 );%0A    %7D

Update Apps.java