gpt4 book ai didi

java - 即使设备所有权设置为此应用程序,也允许使用 pin 取消固定应用程序

转载 作者:行者123 更新时间:2023-12-01 17:59:52 24 4
gpt4 key购买 nike

我正在使用 dpm 命令 (dpm set-device-admin) 为我的应用程序设置设备所有权,并在我的 MainActivity.java 中放置了以下代码:

DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
// get this app package name
ComponentName mDPM = new ComponentName(this, MyAdmin.class);

if (myDevicePolicyManager.isDeviceOwnerApp(this.getPackageName())) {
// get this app package name
String[] packages = {this.getPackageName()};
// mDPM is the admin package, and allow the specified packages to lock task
myDevicePolicyManager.setLockTaskPackages(mDPM, packages);
startLockTask();
} else {
Toast.makeText(getApplicationContext(),"Unable to auto pin - not device owner", Toast.LENGTH_LONG).show();
}

每当我的应用程序启动时,它都会自动固定自身,从而使用户无法离开。在不设置设备所有权的情况下,我可以通过长按后退按钮并提供 pin 来离开“固定”状态。

当我设置所有权时,此操作将被覆盖 - 我看到的只是“应用程序已固定:此设备上不允许取消固定”。有没有什么方法可以通过提供 pin 来启用取消固定,而无需设备所有权?我仍然需要它来确保它在没有任何提示的情况下自动固定。

最佳答案

可能的答案:

成功时覆盖单/长按键、请求固定和取消固定应用

MainActivity.java

@Override
public void onBackPressed() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
Intent intent = km.createConfirmDeviceCredentialIntent(null, null);
if (intent != null) {
startActivityForResult(intent, REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS);
}
}
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) {
// unpin the app
if (resultCode == RESULT_OK) {
stopLockTask();
} else {
// nope
Toast.makeText(this, "Pin is not correct", Toast.LENGTH_SHORT).show();
}
}
}

关于java - 即使设备所有权设置为此应用程序,也允许使用 pin 取消固定应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60655626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com