I have a Redmi Note 8 Pro
I ran the sample app from here ->
https://www.b4x.com/android/forum/threads/device-administrator-library.19208/
Only change was to Update to work against API 30.
Hitting Enable works fine.
However, it then crashes and every time the app is run on
If manager.Enabled And manager.PasswordSufficient Then
Logger connected to: Xiaomi Redmi Note 8 Pro
--------- beginning of system
--------- beginning of crash
--------- beginning of main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 24 (Main)
java.lang.SecurityException: No active admin owned by uid 10347 for policy #0
at android.os.Parcel.createExceptionOrNull(Parcel.java:2376)
at android.os.Parcel.createException(Parcel.java:2360)
at android.os.Parcel.readException(Parcel.java:2343)
at android.os.Parcel.readException(Parcel.java:2285)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.isActivePasswordSufficient(IDevicePolicyManager.java:7476)
at android.app.admin.DevicePolicyManager.isActivePasswordSufficient(DevicePolicyManager.java:3588)
at anywheresoftware.b4a.objects.AdminManager.getPasswordSufficient(AdminManager.java:66)
at anywheresoftware.b4a.samples.admin.main._activity_resume(main.java:403)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.samples.admin.main.afterFirstLayout(main.java:111)
at anywheresoftware.b4a.samples.admin.main.access$000(main.java:17)
at anywheresoftware.b4a.samples.admin.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8043)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.devicepolicy.DevicePolicyManagerService.getActiveAdminOrCheckPermissionForCallerLocked(DevicePolicyManagerService.java:3291)
at com.android.server.devicepolicy.DevicePolicyManagerService.getActiveAdminOrCheckPermissionForCallerLocked(DevicePolicyManagerService.java:3320)
at com.android.server.devicepolicy.DevicePolicyManagerService.getActiveAdminForCallerLocked(DevicePolicyManagerService.java:3298)
at com.android.server.devicepolicy.DevicePolicyManagerService.isActivePasswordSufficient(DevicePolicyManagerService.java:5458)
at android.app.admin.IDevicePolicyManager$Stub.onTransact(IDevicePolicyManager.java:2867)
On a sumsung tablet, android 7.1.1, it works as expected.
On a Pixel 2XL running Android 11, it crashes with the same error as above.