I’ve got Memu emulator (Android 12) rooted.
How do you display an alert dialog like this in Kotlin?
I added codes below but didnt’ work.
<code><uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
</code>
<code><uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
</code>
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
and
<code>fun requestRootAccess(context: Context): Boolean {
return try {
// Try to get root access
val process = Runtime.getRuntime().exec(arrayOf("su", "-c", "id"))
val os = DataOutputStream(process.outputStream)
// Run a simple root command to test
os.writeBytes("idn")
os.flush()
// Wait for the process to finish and get the result code
val resultCode = process.waitFor()
os.close()
if (resultCode == 0) {
// Root access granted, show success message
Toast.makeText(context, "granted", Toast.LENGTH_SHORT).show()
true
} else {
// Root access denied, show failure message
Toast.makeText(context, "denied", Toast.LENGTH_SHORT).show()
false
}
} catch (e: IOException) {
e.printStackTrace()
Toast.makeText(context, "error", Toast.LENGTH_SHORT).show()
false
} catch (e: InterruptedException) {
e.printStackTrace()
Toast.makeText(context, "interrupted", Toast.LENGTH_SHORT).show()
false
}
}
</code>
<code>fun requestRootAccess(context: Context): Boolean {
return try {
// Try to get root access
val process = Runtime.getRuntime().exec(arrayOf("su", "-c", "id"))
val os = DataOutputStream(process.outputStream)
// Run a simple root command to test
os.writeBytes("idn")
os.flush()
// Wait for the process to finish and get the result code
val resultCode = process.waitFor()
os.close()
if (resultCode == 0) {
// Root access granted, show success message
Toast.makeText(context, "granted", Toast.LENGTH_SHORT).show()
true
} else {
// Root access denied, show failure message
Toast.makeText(context, "denied", Toast.LENGTH_SHORT).show()
false
}
} catch (e: IOException) {
e.printStackTrace()
Toast.makeText(context, "error", Toast.LENGTH_SHORT).show()
false
} catch (e: InterruptedException) {
e.printStackTrace()
Toast.makeText(context, "interrupted", Toast.LENGTH_SHORT).show()
false
}
}
</code>
fun requestRootAccess(context: Context): Boolean {
return try {
// Try to get root access
val process = Runtime.getRuntime().exec(arrayOf("su", "-c", "id"))
val os = DataOutputStream(process.outputStream)
// Run a simple root command to test
os.writeBytes("idn")
os.flush()
// Wait for the process to finish and get the result code
val resultCode = process.waitFor()
os.close()
if (resultCode == 0) {
// Root access granted, show success message
Toast.makeText(context, "granted", Toast.LENGTH_SHORT).show()
true
} else {
// Root access denied, show failure message
Toast.makeText(context, "denied", Toast.LENGTH_SHORT).show()
false
}
} catch (e: IOException) {
e.printStackTrace()
Toast.makeText(context, "error", Toast.LENGTH_SHORT).show()
false
} catch (e: InterruptedException) {
e.printStackTrace()
Toast.makeText(context, "interrupted", Toast.LENGTH_SHORT).show()
false
}
}
<code>fun requestRootAccess(context: Context): Boolean {
return try {
// Try to get root access
val process = Runtime.getRuntime().exec(arrayOf("su", "-c", "id"))
val os = DataOutputStream(process.outputStream)
// Run a simple root command to test
os.writeBytes("idn")
os.flush()
// Wait for the process to finish and get the result code
val resultCode = process.waitFor()
os.close()
if (resultCode == 0) {
// Root access granted, show success message
Toast.makeText(context, "granted", Toast.LENGTH_SHORT).show()
true
} else {
// Root access denied, show failure message
Toast.makeText(context, "denied", Toast.LENGTH_SHORT).show()
false
}
} catch (e: IOException) {
e.printStackTrace()
Toast.makeText(context, "error", Toast.LENGTH_SHORT).show()
false
} catch (e: InterruptedException) {
e.printStackTrace()
Toast.makeText(context, "interrupted", Toast.LENGTH_SHORT).show()
false
}
</code>
<code>fun requestRootAccess(context: Context): Boolean {
return try {
// Try to get root access
val process = Runtime.getRuntime().exec(arrayOf("su", "-c", "id"))
val os = DataOutputStream(process.outputStream)
// Run a simple root command to test
os.writeBytes("idn")
os.flush()
// Wait for the process to finish and get the result code
val resultCode = process.waitFor()
os.close()
if (resultCode == 0) {
// Root access granted, show success message
Toast.makeText(context, "granted", Toast.LENGTH_SHORT).show()
true
} else {
// Root access denied, show failure message
Toast.makeText(context, "denied", Toast.LENGTH_SHORT).show()
false
}
} catch (e: IOException) {
e.printStackTrace()
Toast.makeText(context, "error", Toast.LENGTH_SHORT).show()
false
} catch (e: InterruptedException) {
e.printStackTrace()
Toast.makeText(context, "interrupted", Toast.LENGTH_SHORT).show()
false
}
</code>
fun requestRootAccess(context: Context): Boolean {
return try {
// Try to get root access
val process = Runtime.getRuntime().exec(arrayOf("su", "-c", "id"))
val os = DataOutputStream(process.outputStream)
// Run a simple root command to test
os.writeBytes("idn")
os.flush()
// Wait for the process to finish and get the result code
val resultCode = process.waitFor()
os.close()
if (resultCode == 0) {
// Root access granted, show success message
Toast.makeText(context, "granted", Toast.LENGTH_SHORT).show()
true
} else {
// Root access denied, show failure message
Toast.makeText(context, "denied", Toast.LENGTH_SHORT).show()
false
}
} catch (e: IOException) {
e.printStackTrace()
Toast.makeText(context, "error", Toast.LENGTH_SHORT).show()
false
} catch (e: InterruptedException) {
e.printStackTrace()
Toast.makeText(context, "interrupted", Toast.LENGTH_SHORT).show()
false
}
}
New contributor
MICHI DE LOS MONTES is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1