开发学院手机开发Android 开发 Android 获取Launcher 启动列表 阅读

Android 获取Launcher 启动列表

 2010-08-22 04:28:00 来源:WEB开发网   
核心提示:Intent it = new Intent(Intent.ACTION_MAIN);it.addCategory(Intent.CATEGORY_LAUNCHER);List ra =pkgMgt.queryIntentActivities(it,0);for(int i=0;i< p> Activity

Intent it = new Intent(Intent.ACTION_MAIN);

it.addCategory(Intent.CATEGORY_LAUNCHER);

List ra =pkgMgt.queryIntentActivities(it,0);

for(int i=0;i< p>

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);

上一页  1 2 3 4  下一页

Tags:Android 获取 Launcher

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接