Reputation: 1616
I want to lock the application with a specific password specified by the user from the application itself.
For example if it receives the SMS "LOCK WITH PASSWORD abc" it should lock the phone with abc.
I had tried it with device administrator. But it only lock the phone.
The code I used is.....
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);
}
}
Is there any way to make it possible..
Upvotes: 0
Views: 638
Reputation: 2263
you have to use resetPassword
From docs
public boolean resetPassword (String password, int flags)
Force a new device unlock password (the password needed to access the entire device, not for individual accounts) on the user. This takes effect immediately
then call the lock method to lock the device
mDPM.lockNow()
Upvotes: 1