please like & Subscribe our youtube channel
https://www.youtube.com/playlist?list=PLQzJncZC8PUwCTcniu_akzp0N0oDx7l1n
Reboot Device programmatically
We can also reboot any android device with programmatically so here we will reboot android device via ADB command by android programmatically.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
Toast.makeText(getBaseContext(), "Reguler Reboot", Toast.LENGTH_LONG) .show();
} catch (IOException e) {
e.printStackTrace();
}
Reboot to Recovery programmatically
We can also do the reboot to recovery any android device with programmatically so here we will reboot to recovery android device via ADB command by android programmatically.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot recovery" });
Toast.makeText(getBaseContext(), "Reboot to Recovery", Toast.LENGTH_LONG) .show();
} catch (IOException e) {
e.printStackTrace();
}
Reboot to bootloader programatically
We can also do reboot to bootloader any android device with programmatically so here we will reboot to bootloader android device via adb command by android programmatically.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot bootloader" });
Toast.makeText(getBaseContext(), "Reboot to bootloader ", Toast.LENGTH_LONG) .show();
} catch (IOException e) {
e.printStackTrace();
}
Power off Device programatically
Similarly we can switch off any device via programmatically.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot -p" });
Toast.makeText(getBaseContext(), "Power off", Toast.LENGTH_LONG) .show();
} catch (IOException e) {
e.printStackTrace();
}
Factory Reset Device programatically
We can also reset any device with programming.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", " recovery --wipe_data" });
Toast.makeText(getBaseContext(), "Factory Reset", Toast.LENGTH_LONG) .show();
} catch (IOException e) {
}
Storage management Programmatically
We can store our android ROM data in three possible location first in system memory or we can say that ROM memory, the second one is in internal storage or we can say that device internal memory and third one is in external memory with providing by TF card or memory card by default by ADB command but our device should be rooted.
Set as system memory by default
Here we are creating adb command for set default data storage as system programmatically.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "pm set-install-location 0" });
} catch (IOException e) {
}
Set as internal memory by default
Here we are creating adb command for set default data storage as internal memory programmatically.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "pm set-install-location 1" });
} catch (IOException e) {
}
Set as internal memory by default
Here we are creating adb command for set default data storage as internal memory programmatically.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "pm set-install-location 2" });
} catch (IOException e) {
}
check rooted device programmatically in android
If our android device is rooted then We can customize our android ROM with android programming. In this chapter will study about rooting, boot animation maker, boot animation checker and other some programming. Here we are implementing ADB commands in android programming.
Root Checker
We already know that how we can check root status but ADB commands But here we will check root status by android programming. Here we have two conditions that device is rooted externally or internally.
Root Checker externally
For check externally we have to check su or super user file exist in ROM or not.
First method
For check externally we will have to check that su file executes or not.
private boolean canExecuteSuCommand()
{
try
{
Runtime.getRuntime().exec("su");
i = 1;
return i;
}
catch (IOException localIOException)
{
while (true)
int i = 0;
}
}
Or either su file exist or not in xbin folder.
private boolean hassufile()
{
return new File("/system/sbin/su").exists();
}
Second method
The second method we are checking for superuser.apk file exist in app folder or not.
private boolean hasSuperuserApkfile()
{
return new File("/system/app/Superuser.apk").exists();
}
Root Checker internally
For check root status we will have findtest_kesys string exist in buid.prop file which exist in /system/ directory.
private boolean isTestKeyBuild()
{
String str = Build.TAGS;
if ((str != null) && (str.contains("test-keys")));
for (int i = 1; ; i = 0)
return i;
}
Create an application as system application
All system application are located in /system/app/ directory in android rom so if want create our application as system application we will have to insert this application into app directory.
try {
Runtime.getRuntime()
.exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] {"su","-c","cat "+ f + " > /system/app/"+name });
Toast.makeText(getApplicationContext(),"You Suceesfully set"+" "+name+" "+"system app",Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"You need to root access", Toast.LENGTH_LONG).show();
}
Remove an application System application
Similarly we have to remove application form app directory.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] {"su","-c","rm"+" system/app/"+”application name” });
Toast.makeText(getApplicationContext(),"Successfully remove" +" "+name2+" "+"app",Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"You need to root access", Toast.LENGTH_LONG).show();
}
Copy system application
Similarly we can keep backup of any system application.
try {
Runtime.getRuntime().exec(new String[] { "su", "-c","mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /system/" });
Runtime.getRuntime().exec(new String[] { "su", "-c","cat"/system/app/applicationname" > /sdcard/SystemApps/"+name2 });
Toast.makeText(getBaseContext(), "SuceesFully Copy"+name2, Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"You need to root access", Toast.LENGTH_LONG).show();
}