获取正在运行的Launcher的包名

来源:互联网 发布:淘宝登陆不了 编辑:程序博客网 时间:2024/05/27 00:44
/**     * 获取正在运行桌面包名(注:存在多个桌面时且未指定默认桌面时,该方法返回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;        }    }

原创粉丝点击