check if app has Root permission - Android App

Android examples for App:App Information

Description

check if app has Root permission

Demo Code


//package com.java2s;

import java.io.File;

public class Main {
    public static boolean isRoot() {
        final String[] suPathArray = { "/system/bin/", "/system/xbin/",
                "/system/sbin/", "/sbin/", "/vendor/bin/" };
        File file;/*  w  w  w . j  av a 2 s .c  o  m*/
        try {
            for (int i = 0; i < suPathArray.length; i++) {
                String filePath = suPathArray[i] + "su";
                file = new File(filePath);
                if (file.exists()) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related Tutorials