我正在尝试从我的应用程序中清理 Netflix 数据、TV 版 (ninja)。我使用以下代码:
private void clearPreferences() {
try {
// clearing app data
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm clear com.netflix.ninja");
} catch (Exception e) {
e.printStackTrace();
}
}
它编译但没有任何反应。 当我尝试通过控制台执行相同操作时,它可以正常工作:
adb shell pm clear com.netflix.ninja
有什么建议吗?
最佳答案
谢谢大家。我开始在命令中使用“su”。但我必须先对我的设备进行 root。
如果有人需要,请遵循代码:
@OnClick(R.id.clean)
protected void cleanAppData() {
try {
Process p = Runtime.getRuntime().exec("su");
DataOutputStream dos = new DataOutputStream(p.getOutputStream());
dos.writeBytes("pm clear com.netflix.mediaclient\n");
dos.writeBytes("exit\n");
dos.flush();
dos.close();
p.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
关于android - 清理应用程序数据不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45619445/