我想使用用户从应用程序本身指定的特定密码锁定应用程序。
例如,如果它收到短信“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);
}
}
有没有办法让它成为可能..