package com.example.android.apis.view;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import java.util.List;

//Need the following import to get access to the app resources, since this
//class is in a sub-package.
import com.example.android.apis.R;


public class Grid1 extends Activity {

   
GridView mGrid;

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);

        loadApps
(); // do this in onresume?

        setContentView
(R.layout.grid_1);
        mGrid
= (GridView) findViewById(R.id.myGrid);
        mGrid
.setAdapter(new AppsAdapter());
   
}

   
private List<ResolveInfo> mApps;

   
private void loadApps() {
       
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent
.addCategory(Intent.CATEGORY_LAUNCHER);

        mApps
= getPackageManager().queryIntentActivities(mainIntent, 0);
   
}

   
public class AppsAdapter extends BaseAdapter {
       
public AppsAdapter() {
       
}

       
public View getView(int position, View convertView, ViewGroup parent) {
           
ImageView i;

           
if (convertView == null) {
                i
= new ImageView(Grid1.this);
                i
.setScaleType(ImageView.ScaleType.FIT_CENTER);
                i
.setLayoutParams(new GridView.LayoutParams(50, 50));
           
} else {
                i
= (ImageView) convertView;
           
}

           
ResolveInfo info = mApps.get(position);
            i
.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));

           
return i;
       
}


       
public final int getCount() {
           
return mApps.size();
       
}

       
public final Object getItem(int position) {
           
return mApps.get(position);
       
}

       
public final long getItemId(int position) {
           
return position;
       
}
   
}

}

API DEMO 를 이용하여 프로그램 안 Activity 별로 아이콘을 받아와서 표시하는것 까지는 했는데요...
그 아이콘 클릭해서 Activity 뛰우는게 안되네요..ㅠㅠ
mGrid.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
// TODO Auto-generated method stub
startActivity(new Intent(Intent.ACTION_VIEW));
}
        });

이런식으로 했는데 안되네요..ㅠㅠ
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
이 부분을
Intent mainIntent = new Intent(Intent.ACTION_VIEW, null);
로 수정했습니다.

고수님들 방법좀 가리켜주세요...

추가>
mainIntent.addCategory(Intent.CATEGORY_DEFAULT);
CATEGORY_LAUNCHER -> CATEGORY_DEFAULT 로 변경 했더니....
팝업창식으로 실행이 되서 클릭하면 실행은 가능해 지내요...

이 팝업창 안뜨고 실행하는 방법 없나요..??ㅠㅠ