我想使用用户从应用程序本身指定的特定密码锁定应用程序。
例如,如果收到短信“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);
}
}
有没有办法让它成为可能......
答案 0 :(得分:1)
你必须使用resetPassword
来自docs
public boolean resetPassword (String password, int flags)
强制用户使用新设备解锁密码(访问整个设备所需的密码,而不是个人帐户)。这会立即生效
然后调用lock方法来锁定设备
mDPM.lockNow()