使用adb shell清除应用程序数据
adb shell pm clear com.android.browser
Run Code Online (Sandbox Code Playgroud)
但是从应用程序执行该命令时
String deleteCmd = "pm clear com.android.browser";
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(deleteCmd);
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
问题:
虽然我已经给出了以下许可,但它不会清除用户数据也不会给出任何异常.
<uses-permission android:name="android.permission.CLEAR_APP_USER_DATA"/>
Run Code Online (Sandbox Code Playgroud)
题:
如何使用adb shell清除应用程序数据?
到目前为止,我能够通过以下代码使用 root(在应用程序内)安装 APK 文件:
pm install -t -f fullPathToApkFile
Run Code Online (Sandbox Code Playgroud)
如果我想(尝试)安装到 SD 卡:
pm install -t -s fullPathToApkFile
Run Code Online (Sandbox Code Playgroud)
最近,不确定来自哪个 Android 版本(至少在 Android P beta 上存在问题),上述方法失败,向我显示此消息:
avc: denied { read } for scontext=u:r:system_server:s0 tcontext=u:object_r:sdcardfs:s0 tclass=file permissive=0
System server has no access to read file context u:object_r:sdcardfs:s0 (from path /storage/emulated/0/Download/FDroid.apk, context u:r:system_server:s0)
Error: Unable to open file: /storage/emulated/0/Download/FDroid.apk
Consider using a file under /data/local/tmp/
Error: Can't open file: /storage/emulated/0/Download/FDroid.apk
Exception occurred while executing:
java.lang.IllegalArgumentException: Error: Can't open file: /storage/emulated/0/Download/FDroid.apk
at com.android.server.pm.PackageManagerShellCommand.setParamsSize(PackageManagerShellCommand.java:306) …
Run Code Online (Sandbox Code Playgroud)