In this tutorial,we will create a Root App which can Reboot,Reboot Recovery,Restart SystemUI and Shutdown device from scratch using Android Studio and Libsuperuser.
Please make sure what Rooting is,How to Root and Root app from other sources.Otherwise don’t experiment this in device. [Use our open source Root Checker, for verifying your root access.]
Note : This article will not talk about Rooting or How to Root..
Firstly, there are lot things you need to know before coding.It depend upon your coding skills esp in Android Shell Commands.Please note that creating Play Store available app must need more testing in real device.
In this tutorial ,we are using Libsuperuser ( Chainfire).Check examples section and lastly he also added gradle for AS users :).
Libsuperuser
In http://su.chainfire.eu/ , Chainfire () writes about why we need to use this library other than simple Runtime.exec() and How to use this . Please read that documentation ..
See similar libraries from here..
1.Introduction
In this tutorial,we will create RestarterApp from scratch.You need Root Permission for running this App (please make sure that).This app has functions like Restart Device,Restart to Recovery,Restart SystemUI,Shutdown Device.
This app is test Successfully in my Samsung Galaxy S3 running Android 4.4.4 (Kitkat). Please comment result with your device.
2. Requirement
1) Android Studio
2) Libsuperuser
3) Read http://su.chainfire.eu/
4) Rooted Device for real testing.
3. Adding Libsuperuser in AndroidStudio
Gradle :
dependencies {
compile 'eu.chainfire:libsuperuser:1.0.0.+'
}
4. Create Project
1) Create new Android Project by : File => New Project and fill description and click Next.
2) Fill the minimum SDK for the project, i use 4.0+
3) Select Blank Activity and then fill out the details Activity Name and Layout Name then click Finish.
4) For Gradle : You can add Libsuperuser library by adding it on app=>build.gradle (in project view).
5. AndroidManifest.xml
Note :There is no need for adding permissions.
6. activity_main.xml
7. AsyncTask
In this project ,we only need to use doInBackground() (we you need to show dialog,you need to implement preExecute and postExecute).I will explain the process step by step inside :doInBackground(). We pass a string to the Async Task for reboot,restart recovery,shutdown,restart systemui.
1. Firstly, we need to check if root access available or not.If no root access,you cannot execute the command.This step is important because it will initially grant the root permission.
2. Next, we need to write the Android Shell code for each operations. Android Shell Command Reference and ADB Command List will give you some commands list.
3. Running Shell code:
Syntax : Shell.SU.run(command);
Example 1 : Shell.SU.run(“reboot”) ; //This will reboot the device
Example 2 : String suResult = Shell.SU.run(“ls”) ; //This will list files in current directory and will store to suResult
4. After how to run the shell code,now we are back to the project.Here,we will start each operations using a switch case.
8. MainActivity.java
We will call the AsyncTask with passing the string for each operations.
Eg: (new StartUp()).setContext(v.getContext()).execute(“reboot”); //for reboot
Full Code:
9. Conclusion
All credit are given to Chainfire and i only try to explain how to use the library.There are also some open source root apps available in f-droid,check it.I am also beginner in making root app.
You can also try our which is using RootTools ,another root library.
Please use comment box and i will be there to help you.
Please use this project for educational purposes and i will not responsible.
Please Subscribe and Support us.
Pingback: New App Launch : Rebooter Widget - MakeInfo()