1、获取桌面应用
/**
* get all packages of Home apps's
*
* @param context
* @return
*/
public static List<String> getHomePkgs(Context context) {
List<String> homePkgs = new ArrayList<String>();
if (context == null) {
return homePkgs;
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
PackageManager pManager = context.getPackageManager();
List<ResolveInfo> list = pManager.queryIntentActivities(intent, 0);
if (list == null) {
return homePkgs;
}
for (ResolveInfo resolveInfo : list) {
if (resolveInfo != null && resolveInfo.activityInfo.packageName != null) {
homePkgs.add(resolveInfo.activityInfo.packageName);
}
}
return homePkgs;
}
2、获取动态壁纸的应用
/**
* get all liveWallPaper packages
*
* @param context
* @return
*/
public static List<String> getLiveWallpaperPkgs(Context context) {
PackageManager mPackageManager = context.getPackageManager();
List<String> pkgList = new ArrayList<String>();
List<ResolveInfo> list = mPackageManager.queryIntentServices(new Intent(
WallpaperService.SERVICE_INTERFACE), PackageManager.GET_META_DATA);
int listSize = list.size();
for (int i = 0; i < listSize; i++) {
ResolveInfo resolveInfo = list.get(i);
WallpaperInfo info;
try {
info = new WallpaperInfo(context, resolveInfo);
} catch (XmlPullParserException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
continue;
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
continue;
}
if (info != null) {
pkgList.add(info.getPackageName());
}
}
return pkgList;
}
3、获取所有输入法应用
/**
* Get input method packages
*
* @param context
* @return
*/
public static List<String> getInputMethodPkgs(Context context) {
List<String> inputMethodPkgs = new ArrayList<String>();
if (context == null) {
return inputMethodPkgs;
}
InputMethodManager mImm = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (mImm == null) {
return inputMethodPkgs;
}
List<InputMethodInfo> mImis = mImm.getInputMethodList();// get inputmethod information list
if (mImis == null) {
return inputMethodPkgs;
}
String str;
for (InputMethodInfo inputMethodInfo : mImis) {
if ((str = getInputMethodStr(inputMethodInfo.getId())) != null) {
inputMethodPkgs.add(str);
}
}
return inputMethodPkgs;
}