问题
I want to write tests for an application that uses the android device administration API . My problem is that the user needs to manually grant one-time approval for the application to have admin rights, otherwise a SecurityException
is thrown at runtime.
a user can manually enable/disable admin rights for applications by going to settings->location & security -> select device administators. I would like to do it programmatically from within an AndroidTestCase
.
回答1:
I did not find a way to grant admin automatically.
Luckily, however, the AVD remembers that the application was granted admin and does not revoke it after installing a later version of the same app. Thus, after a manual one-time process of enabling admin on the emulator I can run all my tests that require admin, as long as i don't switch to another AVD.
来源:https://stackoverflow.com/questions/5729872/programmatically-enable-android-device-administration