I'm developing a device owner app (which is installed via QR code) In one scenario I need to switch users and that involves clearing all data that is related to the application, if the app wasn't a "device owner app" I would use android
((ActivityManager) m_context.getSystemService(Context.ACTIVITY_SERVICE)).clearApplicationUserData();
but since it is a "device owner app" I'm getting the following error:
java.lang.SecurityException: Cannot clear data for a protected package
Are there any other api / approach to clear data for device owner application?
Update:
Thanks to @CommonsWare I called context.deleteDatabase("db_name")
to all db's and cleared all SharedPreferences like this
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
return editor.commit();
And that's was enough...
You can clear your data "the hard way", by deleting the files that you created or clearing their contents.
You may want to examine your app's portion of internal storage via Android Studio's Device File Manager or adb shell
, to see if there are other files that need to be cleared that you did not create directly (e.g., from WebView
).