I’m currently working on a MAUI-based application and need an effective way to detect whether an Android device is rooted. I’ve tried a couple of approaches, but none seem to work reliably. Here’s what I’ve attempted so far:
1. Simple Approach Using su
Command
I started with a straightforward method to check for root access by executing the su
command:
bool isRooted = Java.Lang.Runtime.GetRuntime().Exec("su").ExitValue() == 0;
However, this approach fails to detect root access. Interestingly, running su
via adb shell
on the same device successfully grants superuser access ($
changes to #
), but the above code doesn’t work as expected.
2. Using a NuGet Package
Next, I tried using a NuGet package called banditoth.MAUI.JailbreakDetector:
This package checks for:
- Presence of superuser executables (e.g.,
su
).
- Known rooting apps installed on the device.
- Write permissions in restricted directories.
Unfortunately, this solution also fails to detect root access on my test device.
Request for Suggestions
I’m looking for a reliable and effective way to detect root access on Android devices using the .NET MAUI framework. If anyone has successfully implemented root detection in a MAUI app, I’d appreciate any guidance or code examples.