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.

Choosing the Best Motherboard

We will look at the various factors you should take into account when choosing your gaming motherboard, to ensure that you choose the best motherboard for your needs.If you think of the processor as the brain of a computer, then the motherboard could be described as the central nervous system, responsible for relaying information between all the internal components. In other words, it’s the hub of the computer, where all other components connect to. Since the motherboard is so crucial to your system, buying the best motherboard you can afford is a good investment. Select Your CPU First Before choosing your motherboard, you should have already chosen your CPU. If you haven’t already doneA motherboard will generally only support one type of processor, such as a Pentium 4 or Athlon 64. Different CPUs have connectors that vary physically from one another. So you can’t accidentally plug in the wrong processor into the wrong motherboard. Also, take note that many motherboards

Choosing the Best CPU for Your Gaming Computer

Picking the latest, fastest or most expensive processor on the market won’t always result in the right CPU for your particular system. Some processors are designed to work with certain motherboards, so the CPU you choose will limit the type of motherboard you can get. The CPU (Central Processing Unit) is one of the most important components in any computer system. The CPU could be described as the brains of a computer. It contains the logic circuitry that performs the instructions of the software you run. The performance of your games and other applications will be directly related to this tiny little microprocessor. The Major Players: Intel and AMD Two companies dominate the CPU market, Intel and AMD (Advanced Micro Devices). Both companies make a range of different processor models.  For example, Intel have the Core i7 and Core i5 processor models, while AMD have the Athlon and Phenom series.  The Best CPU for Gaming If you’re a basic computer user and you don’t