Android获取Launcher 启动列表
2010-06-22 19:18:00 来源:WEB开发网Intent it = new Intent(Intent.ACTION_MAIN);
it.addCategory(Intent.CATEGORY_LAUNCHER);
List
for(int i=0;i
ActivityInfo ai = ra.get(i).activityInfo;
//String ainfo = ai.toString();
Drawable icon = ai.loadIcon(pkgMgt);
String label = ai.loadLabel(pkgMgt).toString();
ComponentName c = new ComponentName(ai.applicationInfo.packageName,ai.name);
LauncherItem item = new LauncherItem(icon,label,c);
lvalue.add(item);
}
}
3. 定义LauncherAdapter 并指定各个item显示样式
Java代码
public class LauncherAdapter extends BaseAdapter {
Activity activity;
public LauncherAdapter(Activity a){
activity = a;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return lvalue.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return composeItem(position);
}
public View composeItem(int position){
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.HORIZONTAL);
ImageView iv = new ImageView(activity);
iv.setImageDrawable(lvalue.get(position).icon);
layout.addView(iv);
TextView tv = new TextView(activity);
tv.setText(lvalue.get(position).name);
赞助商链接