Android安全检查之Activity劫持检测

论坛 期权论坛 脚本     
匿名技术用户   2020-12-23 12:09   11   0

处理检测app进去后台的时候提示用户 也就是在onPause的时候

    /**
     * Is foreground boolean.
     *
     * @param context the context
     * @return the boolean
     */
/*判断应用是否在前台*/
    public static boolean isForeground(Context context) {
        try {
            ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            assert am != null;
            List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
            if (!tasks.isEmpty()) {
                ComponentName topActivity = tasks.get(0).topActivity;
                if (topActivity.getPackageName().equals(context.getPackageName())) {
                    return true;
                }
            }
            return false;
        } catch (SecurityException e) {
            e.printStackTrace();
            return false;
        }
    }
if (!Selfutils.isForeground(this)) {
            setShow(Config.uiStyle + "应用仍在后台运行,如需退出,请先进入"+Config.uiStyle+"应用,按手机“返回键”退出。");
        }
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP