package com.example.keithknight.myandroidlauncher;

import android.app.Activity;
import android.os.Bundle;

/**
 * Created by keithknight on 10/11/15.
 */
public class AppsListActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_apps_list);
    }
}

@@ -93,288 +93,3032 @@
 oid.
-os.Bundle;%0A%0A/**%0A * Created by keithknight on 10/11/15.%0A */%0Apublic class AppsListActivity extends Activity %7B%0A    @Override%0A    protected void onCreate(Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A        setContentView(R.layout.activity_apps_list);%0A    %7D%0A%7D
+content.Intent;%0Aimport android.content.pm.PackageManager;%0Aimport android.content.pm.ResolveInfo;%0Aimport android.graphics.drawable.Drawable;%0Aimport android.os.Bundle;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0Aimport android.widget.AdapterView;%0Aimport android.widget.ArrayAdapter;%0Aimport android.widget.ImageView;%0Aimport android.widget.ListView;%0Aimport android.widget.TextView;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A%0A/**%0A * Created by keithknight on 10/11/15.%0A */%0Apublic class AppsListActivity extends Activity %7B%0A%0A    private PackageManager manager;%0A    private List%3CAppDetail%3E apps;%0A    private ListView list;%0A%0A    @Override%0A    protected void onCreate(Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A        setContentView(R.layout.activity_apps_list);%0A%0A        loadApps();%0A        loadListView();%0A        addClickListener();%0A%0A    %7D%0A%0A    /*%0A    Fetch all the Apps that have a category of Intent.CATEGORY_LAUNCHER%0A     */%0A    private void loadApps() %7B%0A        manager = getPackageManager();%0A        apps = new ArrayList%3CAppDetail%3E();%0A%0A        Intent i = new Intent(Intent.ACTION_MAIN, null);%0A        i.addCategory(Intent.CATEGORY_LAUNCHER);%0A%0A        List%3CResolveInfo%3E availableActivities = manager.queryIntentActivities(i, 0);%0A        for(ResolveInfo ri:availableActivities)%7B%0A            AppDetail app = new AppDetail();%0A            app.label = ri.loadLabel(manager);%0A            app.name = ri.activityInfo.packageName;%0A            app.icon = ri.activityInfo.loadIcon(manager);%0A            apps.add(app);%0A        %7D%0A    %7D%0A%0A    private void loadListView() %7B%0A        list = (ListView)findViewById(R.id.apps_list);%0A%0A        ArrayAdapter%3CAppDetail%3E adapter = new ArrayAdapter%3CAppDetail%3E(this,%0A                R.layout.list_item,%0A                apps) %7B%0A            @Override%0A            public View getView(int position, View convertView, ViewGroup parent) %7B%0A                if(convertView == null)%7B%0A                    convertView = getLayoutInflater().inflate(R.layout.list_item, null);%0A                %7D%0A%0A                ImageView appIcon = (ImageView)convertView.findViewById(R.id.item_app_icon);%0A                appIcon.setImageDrawable(apps.get(position).icon);%0A%0A                TextView appLabel = (TextView)convertView.findViewById(R.id.item_app_label);%0A                appLabel.setText(apps.get(position).label);%0A%0A                TextView appName = (TextView)convertView.findViewById(R.id.item_app_name);%0A                appName.setText(apps.get(position).name);%0A%0A                return convertView;%0A            %7D%0A        %7D;%0A%0A        list.setAdapter(adapter);%0A    %7D%0A%0A    private void addClickListener() %7B%0A        list.setOnItemClickListener(new AdapterView.OnItemClickListener() %7B%0A            @Override%0A            public void onItemClick(AdapterView%3C?%3E av, View v, int pos, long id) %7B%0A                Intent i = manager.getLaunchIntentForPackage(apps.get(pos).name.toString());%0A                AppsListActivity.this.startActivity(i);%0A            %7D%0A        %7D);%0A    %7D%0A%7D%0A
 %0A

Fetch all the Apps that have a category of Intent.CATEGORY_LAUNCHER