Android 获取Launcher 启动列表
2010-08-22 04:28:00 来源:WEB开发网获取Launcher 启动列表
即 列出所有Launcher程序 通过PackageManager 来获取
[代码 步骤]
1. 定义内部类 LauncherItem 用于定义Application相关属性 比如:图标 名称 以及 ComponentName
Java代码
public class LauncherItem {
Drawable icon;
String name;
ComponentName component;
LauncherItem(Drawable d, String s,ComponentName cn){
icon = d;
name = s;
component = cn;
}
};
public class LauncherItem {
Drawable icon;
String name;
ComponentName component;
LauncherItem(Drawable d, String s,ComponentName cn){
icon = d;
name = s;
component = cn;
}
};
2. 定义List
Java代码
public void addLauncher(){
lvalue = new ArrayList
pkgMgt = this.getPackageManager();
//to query all launcher & load into List<>
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);
}
}
public void addLauncher(){
lvalue = new ArrayList
pkgMgt = this.getPackageManager();
//to query all launcher & load into List<>
更多精彩
赞助商链接