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

  • Possible duplicate of [install / uninstall APKs programmatically (PackageManager vs Intents)](https://stackoverflow.com/questions/6813322/install-uninstall-apks-programmatically-packagemanager-vs-intents) – Torben Oct 09 '18 at 06:36
  • @Torben I need to uninstall the app silently without user confirmation. Answers to this question don't provide solutions specifically for my question. – Tharindu Rasanga Oct 09 '18 at 06:44

2 Answers2

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);
}
Mushahid Gillani
  • 723
  • 7
  • 19
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

Mohammed Rampurawala
  • 3,033
  • 2
  • 22
  • 32