How to detect android device is rooted or not in .Net Maui ?

Thombre, Ashish 130 Reputation points
2023-07-19T06:44:44.4566667+00:00

How to detect android device is rooted or not in .Net Maui

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,918 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 48,261 Reputation points Microsoft Vendor
    2023-07-19T08:14:03.46+00:00

    Hello,

    For how to get Android device rooted in MAUI, you can refer to the steps below.

    Step 1. Create a static RootedHelper class in Platforms/Android folder.

    public static class RootedHelper
    {
        public static bool checkRootMethod()
        {
    // If the device is rooted, these paths and files can be accessed.
            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"};
    
            foreach (var s in paths)
            {
                if (File.Exists(s))
                {
                    return true;
                }
            }
            return false;
        }
    }
    

    Step 2. You could invoke this method in MAUI using the following code.

    #if ANDROID
                var rooted = RootedHelper.checkRootMethod();
                if (rooted)
                {
                      Console.WriteLine("rooted");
                }
                else
                {
                      Console.WriteLine("Not rooted");
                }
    #endif
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.