以编程方式启用android设备管理 [英] programmatically enable android device administration

查看:112
本文介绍了以编程方式启用android设备管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为使用android 设备管理的应用程序编写测试API .我的问题是用户需要手动授予一次性批准才能使该应用程序具有管理员权限,否则在运行时会抛出SecurityException.

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.

用户可以通过转到设置->位置&手动为应用程序启用/禁用管理员权限.安全->选择设备管理员.我想从AndroidTestCase内以编程方式进行操作.

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.

推荐答案

我没有找到自动授予管理员权限的方法.

I did not find a way to grant admin automatically.

但是,幸运的是,AVD记住该应用程序已被授予管理员权限,并且在安装了该应用程序的更高版本后并未将其撤消.因此,在手动执行一次在模拟器上启用admin的过程之后,只要我不切换到另一个AVD,我就可以运行所有需要admin的测试.

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.

这篇关于以编程方式启用android设备管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆