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.

Here under is my android-manifest file for the receiver.

 <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>

Below is the code where i am register that seconds for attempt in the activity result

    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);
    }

This is all i have but on devicePolicyManager.setMaximumTimeToLock(devicepolicyAdmin, 50000L); is not setting the time to lock on device.

Girish Acharya
  • 115
  • 1
  • 1
  • 7

1 Answers1

0

Try this(From javadoc):

The calling device admin must have requested USES_POLICY_FORCE_LOCK to be able to call this method; if it has not, a security exception will be thrown.

Check at developer.android.com

RaphMclee
  • 1,623
  • 13
  • 16