Thanks for your answer Erel. I read this in Android documentation:
public boolean resetPassword (
String password,
int flags)
This method was deprecated in API level 30.
Please use
resetPasswordWithToken(ComponentName, String, byte, int) instead.
And i read this about of resetpassword with Token:
resetPasswordWithToken
Added in
API level 26
public boolean resetPasswordWithToken (
ComponentName admin,
String password,
byte[] token,
int flags)
Called by device or profile owner to force set a new device unlock password or a managed profile challenge on current user. This takes effect immediately.
Unlike
resetPassword(String, int), this API can change the password even before the user or device is unlocked or decrypted. The supplied token must have been previously provisioned via
setResetPasswordToken(ComponentName, byte), and in active state
isResetPasswordTokenActive(ComponentName).
The given password must be sufficient for the current password quality and length constraints as returned by
getPasswordQuality(android.content.ComponentName) and
getPasswordMinimumLength(android.content.ComponentName); if it does not meet these constraints, then it will be rejected and false returned. Note that the password may be a stronger quality, for example, a password containing alphanumeric characters when the requested quality is only numeric.
Calling with a null or empty password will clear any existing PIN, pattern or password if the current password constraints allow it.
On devices not supporting
PackageManager#FEATURE_SECURE_LOCK_SCREEN feature, calling this methods has no effect - the password is always empty - and false is returned.
Requires the
PackageManager#FEATURE_SECURE_LOCK_SCREEN feature which can be detected using
PackageManager.hasSystemFeature(String).
Is there a way to update the Device Manager library?
@William Lancee , thanks for your answer, do you see something wrong in my code?:
Sub Process_Globals
Public manager As AdminManager
End Sub
Sub Globals
Dim rp As RuntimePermissions
Dim ComponentName As Object = manager.As(JavaObject).GetField("rec")
Dim DevicePolicyManager As JavaObject = manager.As(JavaObject).GetField("dm")
Dim sr As SecureRandom 'Encryption library
Dim token(32) As Byte
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
rp.CheckAndRequest(rp.PERMISSION_RECEIVE_SMS)
rp.CheckAndRequest(rp.PERMISSION_READ_SMS)
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
If Permission = rp.PERMISSION_RECEIVE_SMS Then
If Result Then
Log("Permission 1") 'Only for control
End If
Else If Permission = rp.PERMISSION_READ_SMS Then
If Result Then
Log("Permission 2") 'Only for control
End If
End If
End Sub
Sub Activity_Resume
' End If
End Sub
Sub btnEnable_Click
If manager.Enabled = False Then
manager.Enable("Please give the access.")
End If
End Sub
Sub btnDisable_Click
manager.Disable
End Sub
Sub btnLock_Click
If manager.Enabled Then manager.LockScreen 'This works
End Sub
Sub btnResetPassword_Click
'manager.ResetPassword("0000") 'This don´t work from Android 30
' DevicePolicyManager.RunMethod("setResetPasswordToken", Array(ComponentName, token)) 'I comment this line
DevicePolicyManager.RunMethod("resetPasswordWithToken", Array(ComponentName, "9876", token, 0))
End Sub
I don't want to upload this to the playstore, it's just a personal project. Any help would be good. Greetings and thanks for the responses.
PS: I find this:
"Sharing my solution here, it may help someone in the future.
In my case, I was receiving the same NPE when I wanted to reset the existing device PIN. (assigned by my device owner application)
I figured out that I had to call setResetPasswordToken() method when the PIN is set for the first time, because isResetPasswordTokenActive() was returning false. I solved it as shown below:"
if (!devicePolicyManager.isResetPasswordTokenActive(DeviceAdminRcvr.getComponentName(this))) {
devicePolicyManager.setResetPasswordToken(DeviceAdminRcvr.getComponentName(this), byteValue);
devicePolicyManager.resetPasswordWithToken(DeviceAdminRcvr.getComponentName(this), firstPassword, byteValue, 0);
} else {
devicePolicyManager.resetPasswordWithToken(DeviceAdminRcvr.getComponentName(this), newPassword, byteValue, 0);
}
Maybe something is wrong in my code.