1

I'm developing a parental control android app which has the ability to uninstall android apps installed on the mobile phone. I referred answers for the question install / uninstall APKs programmatically (PackageManager vs Intents)

I used the following code to uninstall a specific application.

Intent intent = new Intent(Intent.ACTION_DELETE); intent.setData(Uri.parse("package:com.example.tharindurasanga.locationtracker")); startActivity(intent);

This code really works fine but not giving what I'm expecting since this is resulting a prompt saying user to confirm the app uninstallation. I need to uninstall the app silently without user confirmation.

Can someone suggest me another method of doing this or help me to remove this prompt. Note: my device has root permissions too

2

2 Answers 2

2

try this method on rooted device

    try{
    Process su = Runtime.getRuntime().exec("su");
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

    outputStream.writeBytes("pm uninstall package_name\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);
}
Sign up to request clarification or add additional context in comments.

Comments

1

This cannot be done for the 3rd party apps as this privilege is only available to the system apps. This is also not available by JavaReflection.

Refer: Accepted Answer

2 Comments

Is there any method available for rooted devices?
Nope. The user interface will be there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.