0
Runtime.getRuntime(). exec ("dpm set-device-owner com.integral.kiosk.kioskapp/.receivers.MyDeviceAdminReceiver");코드를 사용하지 않는 장치 소유자 설정
Android 에뮬레이터 Nexus 6 OS Android 8에서 기기 소유자를 설정하지 않습니다.하지만 adb 셸 명령을 사용할 때 정상적으로 작동합니다.
다음 코드는 oncreate 함수에서 사용한 코드입니다.
ComponentName deviceAdmin = new ComponentName(this, MyDeviceAdminReceiver.class);
if (!mDevicePolicyManager.isAdminActive(deviceAdmin)) {
Toast.makeText(this, "Not Device Admin", Toast.LENGTH_SHORT).show();
Intent activateDeviceAdmin = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
activateDeviceAdmin.putExtra(
DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin
);
activateDeviceAdmin
.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "After activating admin, you will be able to block application uninstallation.”");
startActivityForResult(activateDeviceAdmin,
PM_ACTIVATION_REQUEST_CODE);
}
if (mDevicePolicyManager.isDeviceOwnerApp(getPackageName())) {
mDevicePolicyManager.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
Toast.makeText(this, "Device Owner", Toast.LENGTH_SHORT).show();
// startLockTask();
mDevicePolicyManager.clearDeviceOwnerApp(getPackageName());
} else {
Toast.makeText(this, "Not Device Owner", Toast.LENGTH_SHORT).show();
try {
Runtime.getRuntime().exec("dpm set-device-owner com.integral.kiosk.kioskapp/.receivers.MyDeviceAdminReceiver");
} catch (IOException e) {
e.printStackTrace();
}
도와주세요. 미리 감사드립니다.