美文网首页Android开发Android开发经验谈Android技术知识
Android系统判断当前界面是否是桌面Launcher

Android系统判断当前界面是否是桌面Launcher

作者: android_Pie | 来源:发表于2020-03-04 16:51 被阅读0次

    Android系统判断当前界面是否是桌面Launcher

    public static boolean isHome(Context context) {

     ActivityManagerm ActivityManager =(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);

    List<ActivityManager.RunningTaskInfo> rti = mActivityManager.getRunningTasks(1);

    return getHomes(context).contains(rti.get(0).topActivity.getPackageName());

        }

    /**

         *获得属于桌面的应用的应用包名称

         *

         * @return返回包含所有包名的字符串列表

         */

        public staticList getHomes(Context context) {

             List<String> names = new ArrayList<String>();

            PackageManagerpackageManager = context.getPackageManager();

            Intent intent = newIntent(Intent.ACTION_MAIN);

            intent.addCategory(Intent.CATEGORY_HOME);

           List<ResolveInfo> resolveInfos =packageManager.queryIntentActivities(intent,

                   PackageManager.GET_INTENT_FILTERS);

            for (ResolveInforesolveInfo : resolveInfos) {

                names.add(resolveInfo.activityInfo.packageName);

            }

            return names;

        }

    相关文章

      网友评论

        本文标题:Android系统判断当前界面是否是桌面Launcher

        本文链接:https://www.haomeiwen.com/subject/drrblhtx.html