1
I am making a device policy app in  android in that we have several task to perform on of the task is:

We want the user to do attempts on screen lock,when 5 attempts been made to user there is 30 seconds timer popup in android system dialog. we want to increase and decrease that seconds to minutes and so on.

We have use 

    DevicepolicyManager.setMaximumTimeToLock(ourDeviceAdmin,50000L);

in the app. But its seems to be not working in emulator as well as real device
so what to do for that in action to run.

下面是我的接收器的 android-manifest 文件。

 <receiver
            android:name="com.zealous.devicepolicy.DemoDeviceAdminReceiver"
            android:permission="android.permission.BIND_DEVICE_ADMIN" >
            <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            </intent-filter>
<meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin_sample" />
</receiver>

下面是我在活动结果中注册该秒以尝试的代码

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
        case ACTIVATION_REQUEST:
            if (resultCode == Activity.RESULT_OK) {
                Log.i("Camera_debug", "Administration enabled!");
                btn.setChecked(true);

                // 50000 equals 50 seconds
                devicePolicyManager.setMaximumTimeToLock(devicepolicyAdmin, 50000L);
            } else {
                Log.i("Camera_Debug", "Administration enable FAILED!");
                btn.setChecked(false);
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

这就是我所拥有的,但在 devicePolicyManager.setMaximumTimeToLock(devicepolicyAdmin, 50000L); 未设置锁定设备的时间。

4

1 回答 1

0

试试这个(来自javadoc):

调用设备管理员必须请求 USES_POLICY_FORCE_LOCK 才能调用此方法;如果没有,将引发安全异常。

在 developer.android.com 上查看

于 2015-04-08T12:48:44.993 回答