首页 > 解决方案 > 有没有办法提示用户输入密码停止锁定任务模式?

问题描述

我想使用锁定任务模式来锁定设备以使用单个应用程序,但能够让用户输入密码以退出锁定任务模式。我更喜欢使用工具栏中的项目来停止锁定任务模式。这些设备本质上是服务提供商用来访问信息的信息亭。它们将分布在全国各地,无法访问互联网,因此我需要一种方法让远程用户将它们从锁定任务模式中解救出来以进行故障排除。任何想法将不胜感激,谢谢。

标签: kotlin

解决方案


我想到了。我创建了一个带有密码输入的警报对话框,使其脱离锁定任务模式。

    private fun showAlertWithTwoButton() {
            val alertDialog = AlertDialog.Builder(this).create()
            alertDialog.setTitle(Constant.ALERTTITLE)
            val input = EditText(this)
            input.hint = "Enter Password"
            input.transformationMethod = PasswordTransformationMethod.getInstance()
            input.inputType = InputType.TYPE_CLASS_TEXT or 
            `enter code here`InputType.TYPE_TEXT_VARIATION_PASSWORD

        alertDialog.setView(input)
        alertDialog.setCanceledOnTouchOutside(true);

        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, Constant.ACCEPT) { 
        dialogInterface, i ->
            val password = input.text.toString()
            if (password == "your password") {
                // Do something here when clicking accept button

        alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, Constant.REJECT) { 
        dialogInterface, i ->
               // Do something here when clicking reject button
            }

        alertDialog.setOnCancelListener(DialogInterface.OnCancelListener {
              // Do something here when clicking outside of alertdialog
        })

        alertDialog.show()
        }

推荐阅读