【发布时间】:2021-12-17 13:05:31
【问题描述】:
是否可以阻止在根设备上安装 android 应用程序?我想阻止在根设备上安装 android 应用程序。怎么做?
【问题讨论】:
标签: android linux flutter android-studio
【问题讨论】:
标签: android linux flutter android-studio
我不知道它是否可以完成,但你可以做的是让你的应用程序在 root 设备上无法使用,这意味着即使安装了用户也无法使用它。
为此,您所要做的就是确定您的应用程序是否在根设备上运行,或者通过以下任何方法(Android 代码)
public class RootUtil {
public static boolean isDeviceRooted() {
return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
}
private static boolean checkRootMethod1() {
String buildTags = android.os.Build.TAGS;
return buildTags != null && buildTags.contains("test-keys");
}
private static boolean checkRootMethod2() {
String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
"/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
for (String path : paths) {
if (new File(path).exists()) return true;
}
return false;
}
private static boolean checkRootMethod3() {
Process process = null;
try {
process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
if (in.readLine() != null) return true;
return false;
} catch (Throwable t) {
return false;
} finally {
if (process != null) process.destroy();
}
}
}
然后如果device is rooted 然后navigate 到一个“ 与exit button 类似“应用程序不能在根设备上运行”的消息。
对于颤振
您可以使用来自pub.dev 的trust_fall 包,
import 'package:trust_fall/trust_fall.dart';
bool isJailBroken = await TrustFall.isJailBroken;
【讨论】: