Skip to main content

Android - Create Root Checker App in Just 10 minutes

Today, I will show you how easily we can create a root checker app in android. It only takes 10 minutes to create this kind of application.

activity_main.xml
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity">    <TextView        android:id="@+id/textView2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="60dp"        android:text="This app checks the rooting status of your phone"        android:textAlignment="center"        android:textSize="18sp"        android:textStyle="bold"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toTopOf="parent" />    <TextView        android:id="@+id/status"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textAlignment="center"        android:textSize="18sp"        android:textStyle="bold"        android:padding="10dp"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toTopOf="parent" />    <Button        android:id="@+id/check"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginBottom="96dp"        android:background="#009688"        android:text="Check"        android:textAlignment="center"        android:textColor="#FAFFFFFF"        android:textSize="14sp"        android:textStyle="bold"        android:typeface="sans"        app:layout_constraintBottom_toTopOf="@+id/status"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toBottomOf="@+id/textView2"        app:layout_constraintVertical_bias="1.0" /></androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.xml

package com.app.rootcheckerapp;import androidx.appcompat.app.AppCompatActivity;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class MainActivity extends AppCompatActivity implements View.OnClickListener {    private Button check;    private TextView status;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        check  = findViewById(R.id.check);        status = findViewById(R.id.status);        check.setOnClickListener(this);    }    @Override    public void onClick(View v) {        if (Helper.isRooted())        {            status.setBackgroundColor(Color.parseColor("#228B22"));            status.setTextColor(Color.parseColor("#FFFFFF"));            status.setText("Device is Rooted");        }        else        {            status.setTextColor(Color.parseColor("#FFFFFF"));            status.setBackgroundColor(Color.parseColor("#B22222"));            status.setText("Device is Not Rooted");        }    }}

The above code is pretty easy. So in MainActivity we have a Check button. On clicking that button, I am calling a helper class method to check the rooting status of the device. This method returns true/false value. If true that means Device is Rooted otherwise not rooted.

And also I am setting the color of the background based on the returned value. If the device is rooted the text background color will be shown in green color otherwise background color will be red.


Helper.java

package com.app.rootcheckerapp;import android.util.Log;public class Helper {public static boolean isRooted(){    Process process = null;    try {        process = Runtime.getRuntime().exec("su");        return true;    }    catch (Exception e)    {        Log.d("Exception", e.toString());         return false;    }    finally {        // Destroy process        if (process != null)        {            process.destroy();        }    }}}

So in the above code, I have written the actual logic. So let’s understand it.

Runtime.getRuntime().exec(“su”);

The above line will execute the shell command su
It is similar to when we execute commands in terminal in Linux


The su stands for superuser. So basically when your device is rooted and you execute su command then it tells the android system and requests for the root access.

But in case if your device is not rooted then it throws an exception
java.io.IOException: Cannot run program “su”: error=13, Permission denied

The exec method returns the object of Process class. So if your android device is not rooted then Runtime.getRuntime().exec(“su”); method will return null . But in case if your android device is rooted then it will return the process object. So it is your duty to destroy the object of process.

That’s why in finally block we are destroying the process by calling process.destroy() method.

How to test the application


Well you can test it in android real devices. But if you don’t have two devices (where one is rooted and the other one is not – rooted). Then we can test it in android emulators too.

Many people say that android emulators are not rooted. But in reality android emulators before lollipop or API Level 21 are actually rooted. So from API level 21 onwards they are not rooted.

Android App Rooted
Android KitKat Emulator
Android App Non rooted
Android Oreo Emulator

Source Code

https://github.com/vaibhavsharma316/TechieVaibhavTutorials/tree/master/RootCheckerApp

Thanks for reading 🙂 🙂

Comments

Popular posts from this blog

3D ANALYZER SETTINGS

Settings for Prince of Persia Sands of Time Works with this game, u can try wid others also which are not in above list Performance section: -force zBuffer Hardware limits: -emulate HW TnL caps -emulate Pixel shader caps ANTI-DETECT MODE section: -shaders Z-buffer section: -24 bit zbuffer(with stencil) DirectX DeviceID’s section: NVIDIA GeForce Ti4600 Configuration: VendorID : 4318 Device ID :592 Works well in the following or higher configuration -Intel 865GSA motherboard, -512 MB RAM, -Pentium D dual core 2.66 GHz processor, -No graphics card required…….. have fun.

SMACKDOWN HERE COMES THE PAIN PCSX2 SETTINGS

Smack Down Here Comes The Pain Configuration: GRAPHICS-GSDX 1600(MSVC 15.00 SSSE3)0.1.15 CONTROLLERS-LILLY PAD 0.10.0 CDVDROM-EPP POLLING CDVD DRIVER 0.4.0 USB-USB NULL DRIVER 0.6.0 SOUND-SPU2-X1.1.0 SECOND CONTROLLER-LILLY PAD 0.10.0 DEV9-DEV9NULL DRIVER-0.4.0 FIRE WIRE-FWNULL DRIVER 0.5.0 BIOS-EUROPE V01.60(04/10/2001)CONSOLE SYSTEM REQUIREMENTS FOR PCSX2- MINIMUM - * Windows/Linux OS * CPU: Any that supports SSE2 (Pentium 4 and up, Athlon64 and up) * GPU: Any that supports Pixel Shader model 2.0, except Nvidia FX series (broken SM2.0, too slow anyway) * 512mb RAM (note Vista needs at least 2gb to run reliably) RECOMMENDED - * Windows Vista 32bit/64bit with the latest DirectX * CPU: Intel Core 2 Duo @ 3.2ghz or better * GPU: 8600gt or better (for Direct3D10 support) * RAM: 1gb on Linux/Windows XP, 2gb or more on Vista MY SYSTEM REQUIREMENTS WINDOWS XP SP3 PENTIUM DUAL CORE 2.6GHZ (E5300) 2GB RAM ZOTAC 8400GS 512MB DIRECT-X 9...

list of games runs on 3d analyser

18 Wheels of Steel : Extreme Trucker (Use addgame. reg tweak and select DirectX in the game's settings window. Tested on win7) A Africa Corps vs. Desert Rats ( XP ONLY) Age of Empires II The Age of Kings + The Conquero rs Expansio n Age of Empires III + The Warchief s + The Asian Dynastie s Age of Mytholog y + Titans Expansio n Aggressi on: Reign Over Europe (Using 3DAnalyz er: all textures work but too slow. FPS is unplayab le status. Try Swiftwsh ader) Aion Online AirStrik e 3D II Alpha Prime Alien Shooter Alien Shooter 2 America's Secret Operatio ns Anno 1404 Dawn Of Discover y (3D Analyzer-Emulate Hardware Tnl) Area 51 (Version 1.2 patch) Armies of Exigo (Works with Medium Settings with Swiftsha der) ASHES Cricket 2009 - Demo (Windows 7 with modded driver and 'addgame. reg' Tweak) Audiosur f Avencast-Rise of the mage Armed and Dangerou s (3DAnalyz e) Attack on Pearl Harbor ( Dogfight game, playable at pretty high setting) B ...