/**
* 获取正在运行桌面包名(注:存在多个桌面时且未指定默认桌面时,该方法返回Null,使用时需处理这个情况)
*/
public static String getLauncherPackageName(Context context) {
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0);
if (res.activityInfo == null) {
// should not happen. A home is always installed, isn't it?
return null;
}
if (res.activityInfo.packageName.equals("android")) {
// 有多个桌面程序存在,且未指定默认项时;
return null;
} else {
return res.activityInfo.packageName;
}
}android获取当前正在运行的桌面launcher包名
最新推荐文章于 2025-07-30 11:29:56 发布
本文介绍了一种通过发送特定意图并解析返回的活动信息来获取当前设备上正在运行的桌面应用包名的方法。当存在多个桌面应用且未指定默认项时,此方法将返回空值。
1625

被折叠的 条评论
为什么被折叠?



