0

我想使用用户从应用程序本身指定的特定密码锁定应用程序。

例如,如果它收到短信“LOCK WITH PASSWORD abc”,它应该用 abc 锁定手机。

我曾与设备管理员尝试过。但它只会锁定手机。

我使用的代码是......

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); 
                filter.addAction(Intent.ACTION_SCREEN_OFF);

                ComponentName mAdminName = new ComponentName(ScreenLockService.this,LockActivity.class);

                if(!mDPM.isAdminActive(mAdminName))
                {
                    Intent intent1 = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                    intent1.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
                      intent1.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"is locked");
                      intent1.putExtra("force-locked", DeviceAdminInfo.USES_POLICY_FORCE_LOCK);

                    context.startActivity(intent1);
                    System.out.println("The Device Could not lock because device admin not enabled");
                    Toast.makeText(getApplicationContext(), "Activate The DeviceAdmin and then Click start Again", Toast.LENGTH_LONG).show();
                    //mDPM.lockNow();
                }
                else
                {
                    System.out.println("The Device  device admin enabled");
                    Intent  intent1 = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                    intent1.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
                    intent1.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"onEnabled");
                    mDPM.lockNow();
                    mDPM.setMaximumTimeToLock(mAdminName, 0);
                    intent1.putExtra("force-locked", DeviceAdminInfo.USES_POLICY_FORCE_LOCK);
                    context.startActivity(intent1); 
}
}

有没有办法让它成为可能..

4

1 回答 1

1

你必须使用 resetPassword

来自文档

public boolean resetPassword (String password, int flags)

强制用户使用新的设备解锁密码(访问整个设备所需的密码,而不是单个帐户的密码)。这立即生效

然后调用lock方法锁定设备

mDPM.lockNow()

于 2013-04-22T09:16:31.647 回答