我在我的 Android 应用程序中使用设备策略管理器,但 Honeycomb 设备有问题。尝试调用 resetPassword 时抛出异常。在 Froyo 或 Gingerbread 中情况并非如此,因为它们都可以正常工作。
错误是:
java.lang.RuntimeException: 无法启动接收器 Package.Name.Test: java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/secure from pid=x, uid= y 需要 android.permission.WRITE_SETTINGS
我的安卓代码如下:
DevicePolicyManager mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if ((mDPM.getActiveAdmins() != null) && (mDPM.isAdminActive(new ComponentName(context, DeviceAdmin.class)))) {
mDPM.resetPassword(extra, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
mDPM.lockNow();
} else {
Log.d(TAG, "Could not lock because device admin not enabled");
}
问题发生在:
mDPM.resetPassword(extra, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
我的 Device_Admin.xml 是:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<force-lock />
<wipe-data />
<reset-password />
</uses-policies>
</device-admin>
就像我说的设备管理员在 Froyo 和 Gingerbread 设备上工作得很好,虽然我确实对使用不同键盘保护的用户有一些问题,例如 Droid X 和 HTC Sense。这个问题与时间有关。当我调用 lockNow 时,设备将关闭屏幕,但 HTC Sense 或 MotoBlur 不会真正锁定键盘锁,直到在设置、安全、锁定电话之后设置的时间。
任何帮助都是极好的!我最近在 I/O 上买了一个蜂窝平板电脑,还没有在这个设备上测试过这个应用程序,但是我在市场网站上看到了运行 Xoom 3.0 的用户的错误。还没有看到任何 3.1 设备。