how to uninstall apps on my rooted phone - android

I tried to uninstall apps on my rooted phone,and I usethe code from How to uninstall Android App with root permissions? ,and I tried the suggestion but I failed.
Here is my code:
Process process;
try {
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("pm uninstall com.lixiancheng.orangemusic"+"; \n");
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
Why i can't uninstall the app?is any problem with the code?

Have You tried:
try {
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("pm uninstall com.lixiancheng.orangemusic\n");
outputStream.flush();
outputStream.writeBytes("exit\n");
outputStream.flush();
su.waitFor();
} catch(IOException e){
throw new Exception(e);
} catch(InterruptedException e){
throw new Exception(e);
}

Type adb shell rm -f/{data,system}/app/APKNAME”, replace “APKNAKE” with the name of the application you want to delete and press Enter.

Related

pm grant <PACKAGE_NAME> <PERMISSION_NAME> not working

I have a weird problem. Last week I had my code working like a charm. I'm working on a rooted tablet, and I'm setting Debug Mode on from code, but no idea why, I ran my app this morning and the command I'm using to to this doesn't work anymore, I get "Permission Denial etc.." BUT, when I type the command from my device's terminal, it works... Any help ?
private void grantPermission(){
try {
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
Log.e("PACKAGE", getPackageName());
os.writeBytes("adb shell" + "\n");
os.flush();
os.writeBytes("pm grant "+getPackageName()+" android.permission.CHANGE_CONFIGURATION" + "\n");
os.flush();
os.writeBytes("pm grant "+getPackageName()+" android.permission.WRITE_SECURE_SETTINGS" + "\n");
os.flush();
} catch (Exception e){
e.printStackTrace();
Log.e("SETTINGS", "FAIL");
}
}
Here it is! I finally fixed it out ! The permission wasn't set fast enough until the call, I simply added a call to the processe's waitFor() method and it worked again. But I still wonder why it used to work before !
private void grantPermission(){
try {
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
os.writeBytes("pm grant "+this.getPackageName()+" android.permission.WRITE_SECURE_SETTINGS" + "\n");
os.writeBytes("pm grant "+this.getPackageName()+" android.permission.CHANGE_CONFIGURATION" + "\n");
os.writeBytes("exit\n");
os.flush();
suProcess.waitFor();
} catch (Exception e){
e.printStackTrace();
}
}

How to uninstall android system app programmatically?

I can get a list of installed apps (both user and system apps). I am also able to uninstall user apps, however, not able to uninstall system apps.
Is there any way to uninstall system app?
If the phone is already rooted, will the following code work?
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:"+appPackageName.getText().toString()));
context.startActivity(intent);
you can execute root commands with:
runCommand("su");
runCommand("rm /data/system/application.package.apk");
runCommand("rm /data/data/application.package");
//when this doesn´t work try
runCommand("rm -r /data/system/application.package.apk");
runCommand("rm -r /data/data/application.package");
public static void runCommand(String command){
try {
Process chmod = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(
new InputStreamReader(chmod.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
chmod.waitFor();
outputString = output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
There is also a nice library: https://github.com/Free-Software-for-Android/RootCommands
You need to have root access in order to remove system or vendor apps.
$ su
# rm /data/system/application.package.apk
# rm /data/data/application.package
Try this on Rooted Device...it works
Process reboot = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(reboot.getOutputStream());
os.writeBytes("pm uninstall co.example.demo\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
reboot.waitFor();

How can I write a simple script on android

Is it possible on an Android terminal tou run a simple script?
I'd like to run the following commands
$su
$cd /Downloads
Try something like this:
try{
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("screenrecord --time-limit 10 /sdcard/MyVideo.mp4\n");
outputStream.flush();
outputStream.writeBytes("exit\n");
outputStream.flush();
su.waitFor();
}catch(IOException e){
throw new Exception(e);
}catch(InterruptedException e){
throw new Exception(e);
}
read this SO question also.
Yes, search the app store for terminal emulator.

Android super user access in app to run commands

I want to run tap cmd like over 100 times and by using code below it will call su everytime and delay taps. So is it possible to request su when app first starts then run many commands fast? thanks!
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
String cmd = "/system/bin/input tap 350 370\n";
os.writeBytes(cmd);
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
}
This is the solution:
try {
Process process = Runtime.getRuntime().exec("su");
OutputStream out = process.getOutputStream();
String cmd = "input tap 350 370";
out.write(cmd.getBytes());
out.flush();
out.close();
process.waitFor();
} catch (IOException e) {
} catch (InterruptedException e) {
}
It worked for me

Trying to reboot programmatically rooted Android device

I'm trying to reboot programmatically my Galaxy S3.
Things that I've tried:
try {
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
proc.waitFor();
} catch (Exception ex) {
Log.i("RebootActivity", "Could not reboot", ex);
}
try {
Runtime.getRuntime().exec(new String[]{"su","-c","reboot now"});
} catch (IOException e) {
e.printStackTrace();
}
try
{
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("reboot now\n");
}
catch (Throwable t)
{
t.printStackTrace();
}
Do you guys have any idea how to accomplish this?
Thanks.
Try to do one normal string looking like 《su \n reboot; \n》 instead of an array.
Try to get the answer from the shell, that helps a lot for debugging.
What are the permissions of your su binary? If they would be wrong, you could try to 《chmod 7777 /system/xbin/su》 after 《mount -o remount,rw /system》
Here is some example code: (to run the string command, which is a \n and or ; separated list of linux shell commands)
StringBuffer commandOutput = new StringBuffer();
try {
Process process = Runtime.getRuntime().exec("su\n");
DataOutputStream out = new DataOutputStream(process.getOutputStream());
out.writeBytes("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/vendor/lib:/system/lib\n");
out.writeBytes(command+"\n");
out.flush();
process.waitFor();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
int numRead;
char[] buffer = new char[1000];
while ((numRead = in.read(buffer)) > 0) {
commandOutput.append(buffer, 0, numRead);
}
in.close();
process.waitFor();
} catch ...
return commandOutput.toString();
You could possibly use the PowerManager to make it reboot (this does not guarantee that it'll reboot - OS may cancel it):
http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String
http://developer.android.com/reference/android/Manifest.permission.html#REBOOT

Categories

Resources