我正在开发一个家长控制 android 应用程序,它能够卸载安装在手机上的 android 应用程序。我提到了问题的答案 install / uninstall APKs programmatically (PackageManager vs Intents)
我使用以下代码卸载特定应用程序。
Intent intent = new Intent(Intent.ACTION_DELETE); intent.setData(Uri.parse("package:com.example.tharindurasanga.locationtracker"));
启动 Activity ( Intent );
这段代码确实工作正常,但没有达到我的预期,因为这会提示用户确认应用程序卸载。我需要在没有用户确认的情况下静默卸载应用。
有人可以建议我执行此操作的另一种方法或帮助我删除此提示。注意:我的设备也有root权限
最佳答案
在root 设备 上试试这个方法
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);
}
关于java - 如何在没有用户交互的情况下以编程方式卸载 Android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52714539/