如何使用我的应用程序以编程方式将密码屏幕锁定到Android手机

时间:2015-02-01 07:36:59

标签: android

我使用下面的代码来设置密码屏幕锁...但是当调用该活动时,我的应用程序崩溃了。 我是否需要在Android清单中添加任何权限?我该怎么做?

public class LockDevice extends Activity{

    public static DevicePolicyManager  devicePolicyManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        DevicePolicyManager devicePolicyManager =(DevicePolicyManager)getApplicationContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
            ComponentName demoDeviceAdmin =new ComponentName(this, LockDevice.class);

            devicePolicyManager.setPasswordQuality(demoDeviceAdmin,DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
            devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 5);

            boolean result = devicePolicyManager.resetPassword("123456", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);

            Toast.makeText(this, "button_lock_password_device..."+result,  Toast.LENGTH_LONG).show();   
    }

}

0 个答案:

没有答案