如何調用此時,爲了避免這種異常避免了因「歸無主動管理」的拋出:SecurityException
E/AndroidRuntime(26113): Caused by: java.lang.SecurityException: No active admin owned by uid XXXX for policy #3
:
public static void lockScreen(Context context) {
Log.d(TAG, "lockScreen");
ComponentName mDeviceAdminSample = null;
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
dpm.lockNow();
}