各位,我想实现一个功能,就是获得android手机系统的所有应用程序的列表,并显示出来。
请问,谁有类似的源代码,发给我看看,谢谢

解决方案 »

  1.   

    这个太多了baidu一大堆。
    算了,给我的代码你看看
     * Method name: dealLauncher<BR>
     * Method description: 显示Dialog[启动应用程序]<BR>
     * 
     */ 
    private void dealLauncher(){
    ImageView appViewBtn= (ImageView)this.findViewById(R.id.ss_02_04_img02);
    appViewBtn.setOnClickListener(new OnClickListener(){ public void onClick(View v) {
    // TODO Auto-generated method stub
    // 1. init UI
    Context context=v.getContext();
    LayoutInflater mInflater = (LayoutInflater) context
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = mInflater.inflate(R.layout.view, null); 
    LinearLayout layout=(LinearLayout)view.findViewById(R.id.LinearLayout01);
    ListView listView=new ListView(context);
    // listView.setDividerHeight(2);
    listView.setCacheColorHint(0);
    // 2.upLoad data
    listView.setAdapter(new LauncherAdapter(v.getContext(), getLaunchers()));
    listView.setItemsCanFocus(false);
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    layout.addView(listView); // 3. show UI
    new AlertDialog.Builder(context)
    .setTitle(R.string.schedule_set_activity_choose_application)//"启动程序设置"
    .setView(view)
    .setPositiveButton(R.string.common_ok,   //"确定"
            new DialogInterface.OnClickListener() {   
                public void onClick(DialogInterface dialog, int which) { 
                 if(launcherItem != null){
                 TextView textView02 = (TextView) ScheduleSetActivity.this.findViewById(R.id.ss_02_04_textView02);
                 textView02.setText(launcherItem.label);
                 }
                
                }   
            })
    .setNegativeButton(R.string.common_cancel,  // "取消"
            new DialogInterface.OnClickListener() {   
                public void onClick(DialogInterface dialog, int which) {   
                 launcherItem = null;
                }   
            }) 
    .show();
    }

    });
    }/** 
         * Class name:LauncherAdapter 
         * Class description:应用程序对应的适配器<BR>
        
         * @version 1.00 2011/03/01
         * @author XXX
         */ 
        private class LauncherAdapter extends BaseAdapter {   
    private LayoutInflater mInflater;
            private ArrayList<LauncherItem> dataSource;        public LauncherAdapter(Context context, ArrayList<LauncherItem> dataSource){   
                this.mInflater = LayoutInflater.from(context); 
                this.dataSource = dataSource;
            }   
               
            public int getCount() {   
                // TODO Auto-generated method stub   
                return dataSource.size();   
            }   
      
            public Object getItem(int arg0) {   
                // TODO Auto-generated method stub   
                return arg0;   
            }   
      
            public long getItemId(int position) {   
                // TODO Auto-generated method stub   
                return position;   
            }   
            
            @Override
    public boolean isEnabled(int position) {
    return false;
    }  
            public View getView(int position, View convertView, ViewGroup parent) {   
                // TODO Auto-generated method stub   
             ViewHolder holder=null;

    if(convertView == null){
    holder=new ViewHolder();  
    convertView=mInflater.inflate(R.layout.list_item_001,null);
    holder.imageView=(ImageView) convertView.findViewById(R.id.li001_img001);
    holder.textView = (TextView) convertView.findViewById(R.id.li001_tv001);
    holder.radioBtn = (RadioButton) convertView.findViewById(R.id.li001_rb001);
    convertView.setTag(holder);   }else {  
    holder = (ViewHolder)convertView.getTag();  
    }  
    holder.imageView.setImageDrawable(dataSource.get(position).icon);
    holder.textView.setText(dataSource.get(position).label);
    holder.radioBtn.setOnClickListener(new SingleChoiceListener(position));
    holder.radioBtn.setChecked(dataSource.get(position).checked);
             return convertView;
            }     
      

  2.   

    我们可以用PackageManager来显示系统安装的应用程序列表或者系统程序列表http://www.iteye.com/topic/1114025
      

  3.   

    我用的这个:http://www.linuxidc.com/Linux/2011-09/42287.htm