如何防止有 Root 权限的 Android 手机安装我的应用程序? [英] How to prevent Rooted Android Phones from Installing my app?

查看:81
本文介绍了如何防止有 Root 权限的 Android 手机安装我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此上下文中的目的是防止在排行榜中报告虚假高分(我的应用程序是游戏).这发生在 Flappy Birds 上 - 请参阅此链接 - http://www.androidpit.com/forum/589832/flappy-bird-high-score-cheat-set-your-own-high-score

The purpose in this context is to prevent false high scores(my app is a game) from being reported in LeaderBoard. This occurred for Flappy Birds - see this link - http://www.androidpit.com/forum/589832/flappy-bird-high-score-cheat-set-your-own-high-score

由于 root 用户可以用他的手机做任何他想做的事情,我想其他解决方法都不起作用,唯一的解决方案是阻止 root 用户安装应用程序.我对吗?有没有办法做到这一点?

Since a root user can do anything he wants with his mobile, I suppose none of the other work around will work and the only solution is to prevent rooted users from installing the app. Am I right? Is there a way to do it?

PS:我的游戏并不总是需要互联网连接,因此当它发生在另一台服务器上时报告分数是不可行的.只有当互联网连接可用时,高分才会报告给排行榜.

PS: My game doesn't need internet connection always, hence reporting the scores as and when it happens to another server is not viable. The high scores are reported to leaderboard only when internet connection is available.

推荐答案

我也有类似的需求.我无法实现应用程序不应安装在有 root 权限的设备上,但我为此使用了一个解决方法:

I had a similar requirement. I couldn't achieve that app should not be installed on rooted device, but I used a work around for that:

  • 检查您的设备是否植根于您活动的 onResume.
  • 如果它已 root,只需向他显示警告此设备已 root.您无法使用此应用程序.",然后退出应用程序.

示例:

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    if(new DeviceUtils().isDeviceRooted(getApplicationContext())){
        showAlertDialogAndExitApp("This device is rooted. You can't use this app.");
    }
}


public void showAlertDialogAndExitApp(String message) {

    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setTitle("Alert");
    alertDialog.setMessage(message);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_HOME);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    finish();
                }
            });

    alertDialog.show();
}

DeviceUtis.java 是一个实用程序类,如果设备是否被 root 则返回.

DeviceUtis.java was a Utility class which returned if a device is rooted or not.

public class DeviceUtils {

    public Boolean isDeviceRooted(Context context){
        boolean isRooted = isrooted1() || isrooted2();
        return isRooted;
    }

    private boolean isrooted1() {

        File file = new File("/system/app/Superuser.apk");
        if (file.exists()) {
            return true;
        }
        return false;
    }

    // try executing commands
    private boolean isrooted2() {
        return canExecuteCommand("/system/xbin/which su")
                || canExecuteCommand("/system/bin/which su")
                || canExecuteCommand("which su");
    }
}

我们使用了 5 种方法进行测试,我在这里只展示了 2 种.您可以使用任何您认为好的方法.

We had used 5 methods for testing, and I have just shown 2 here. You can use any of methods you find good.

希望这会有所帮助.

PS:我已经把这个调用放在所有活动的 onResume 中,因为用户(有黑客意图)可以安装应用程序,导航到其他活动,然后根设备.

P.S: I have put this call in all activity's onResume as user (with intention of hacking) can install application, navigate to some other activity, and then root device.

这篇关于如何防止有 Root 权限的 Android 手机安装我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆