作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在开发需要特殊权限的系统应用程序。出于某种原因,我无法获得 CLEAR_APP_USER_DATA 权限,但我可以使用 INSTALL_PACKAGES、DELETE_PACKAGES 等。这可能是什么原因造成的?
list :
uses-permission android:name="android.permission.CLEAR_APP_USER_DATA"/>
uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>
uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
uses-permission android:name="android.permission.DELETE_PACKAGES"/>
uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/>
uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
我删除了“<”,因为它不会显示其余的行。
我使用权限的代码:
String apkPackage = intent.getExtras().getString(context.getString(R.string.key_package));
if (apkPackage != null) {
PackageManager pm = context.getPackageManager();
Class<?>[] types = new Class[] {String.class, IPackageDataObserver.class};
try {
Method methodClearUserData = pm.getClass().getMethod("clearApplicationUserData", types);
methodClearUserData.invoke(pm, new Object[] {apkPackage, null});
Method methodDeleteCache = pm.getClass().getMethod("deleteApplicationCacheFiles", types);
methodDeleteCache.invoke(pm, new Object[] {apkPackage, null});
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
Log.w(TAG, "Unable to invoke clear method.", e);
}
} else {
Log.w(TAG, "Provided APK package is null.");
}
[编辑]
07-15 14:29:32.136: W/RequestReceiver(4367): Unable to invoke clear method.
07-15 14:29:32.136: W/RequestReceiver(4367): java.lang.reflect.InvocationTargetException
07-15 14:29:32.136: W/RequestReceiver(4367): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 14:29:32.136: W/RequestReceiver(4367): at java.lang.reflect.Method.invoke(Method.java:525)
07-15 14:29:32.136: W/RequestReceiver(4367): at com.test.appmanager.RequestReceiver.onReceive(RequestReceiver.java:114)
07-15 14:29:32.136: W/RequestReceiver(4367): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2558)
07-15 14:29:32.136: W/RequestReceiver(4367): at android.app.ActivityThread.access$1500(ActivityThread.java:165)
07-15 14:29:32.136: W/RequestReceiver(4367): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
07-15 14:29:32.136: W/RequestReceiver(4367): at android.os.Handler.dispatchMessage(Handler.java:107)
07-15 14:29:32.136: W/RequestReceiver(4367): at android.os.Looper.loop(Looper.java:194)
07-15 14:29:32.136: W/RequestReceiver(4367): at android.app.ActivityThread.main(ActivityThread.java:5370)
07-15 14:29:32.136: W/RequestReceiver(4367): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 14:29:32.136: W/RequestReceiver(4367): at java.lang.reflect.Method.invoke(Method.java:525)
07-15 14:29:32.136: W/RequestReceiver(4367): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
07-15 14:29:32.136: W/RequestReceiver(4367): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-15 14:29:32.136: W/RequestReceiver(4367): at dalvik.system.NativeStart.main(Native Method)
07-15 14:29:32.136: W/RequestReceiver(4367): Caused by: java.lang.SecurityException: Neither user 10070 nor current process has android.permission.CLEAR_APP_USER_DATA.
07-15 14:29:32.136: W/RequestReceiver(4367): at android.os.Parcel.readException(Parcel.java:1425)
07-15 14:29:32.136: W/RequestReceiver(4367): at android.os.Parcel.readException(Parcel.java:1379)
07-15 14:29:32.136: W/RequestReceiver(4367): at android.content.pm.IPackageManager$Stub$Proxy.clearApplicationUserData(IPackageManager.java:2918)
07-15 14:29:32.136: W/RequestReceiver(4367): at android.app.ApplicationPackageManager.clearApplicationUserData(ApplicationPackageManager.java:1177)
07-15 14:29:32.136: W/RequestReceiver(4367): ... 14 more
最佳答案
更改设备中的设置,然后它就可以正常工作了。
我们启用开发者选项的方式与我们将有一个选项(USB 调试(安全设置))的方式相同,因此请打开它。
不同设备的选项可能不同。
例如:Redmi Note 5 Pro - 您可以在设置 --> 其他设置 --> 开发人员选项 --> USB 调试中找到
关于android - 无法获取 android.permission.CLEAR_APP_USER_DATA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24755341/
我正在开发需要特殊权限的系统应用程序。出于某种原因,我无法获得 CLEAR_APP_USER_DATA 权限,但我可以使用 INSTALL_PACKAGES、DELETE_PACKAGES 等。这可能
我是一名优秀的程序员,十分优秀!