코틀린 버전
private fun isRooted(): Boolean {
val buildTags = android.os.Build.TAGS
if (buildTags != null && buildTags.contains("test-keys")) {
return true
}
try {
val file = File("/system/app/Superuser.apk")
if (file.exists()) {
return true
}
} catch (e: Exception) {
}
val rootBinaryPaths = arrayOf(
"/sbin/su", "/system/bin/su", "/system/xbin/su", "/system/sd/xbin/su",
"/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"
)
for (path in rootBinaryPaths) {
try {
val file = File(path)
if (file.exists()) {
return true
}
} catch (e: Exception) {
}
}
return false
}
자바 버전
public boolean isRooted() {
Process process = null;
try {
process = Runtime.getRuntime().exec("su -c ls /data");
return process.waitFor() == 0;
} catch (Exception e) {
return false;
} finally {
if (process != null) {
process.destroy();
}
}
}
if(isRooted()){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder
.setMessage("루트권한을 가진 디바이스에서는 실행할 수 없습니다.")
.setCancelable(false)
.setPositiveButton("확인",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog, int id) {
moveTaskToBack(true);
finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
return;
}
'안드로이드 개발 > 개발팁' 카테고리의 다른 글
| 함수의 마지막 인자로 람다를 쓰는 이유 (0) | 2023.11.01 |
|---|---|
| 안드로이드스튜디오 애뮬레이터 죽어도 실행안될때 (2) | 2023.10.30 |
| MediaBrowserService 와 MediaSessionCompat 을 이용해서 exoplayer 만들기 (0) | 2023.10.26 |
| remember 와 rememberSaveable 의 차이 (0) | 2023.10.25 |
| companion object 싱글턴과 커스텀 싱글턴의 차이 (0) | 2023.10.24 |