gpt4 book ai didi

android - 如何防止 Root 的 Android 手机安装我的应用程序?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:56:32 24 4
gpt4 key购买 nike

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

由于 root 用户可以用他的手机做任何他想做的事,我想其他解决方法都行不通,唯一的解决方案是阻止 root 用户安装该应用程序。我对吗?有办法吗?

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

最佳答案

我也有类似的需求。我无法做到应用程序不应安装在已获得 root 权限的设备上,但我使用了一个解决方法:

  • 检查您的设备是否在您的 Activity 的 onResume 中 Root 。
  • 如果已获得 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 是一个 Utility 类,它在设备是否已获得 root 权限时返回。

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 种。您可以使用任何您认为好的方法。

希望这对您有所帮助。

P.S:我已将此调用放在所有 Activity 的 onResume 中,因为用户(有黑客 Intent )可以安装应用程序,导航到其他 Activity ,然后 root 设备.

关于android - 如何防止 Root 的 Android 手机安装我的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27540545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com