打开相机前显示对话框

dki*_*kid 2 alert camera android popup kotlin

我想在相机打开之前显示一条消息。

现在用户单击一个按钮,消息显示 1 秒钟,然后相机立即打开。一旦我关闭相机,对话框仍然可见。

我希望只有在您单击警报消息上的“确定”后才能打开相机,并且一旦您关闭相机,就不再显示该消息。

//Button Picture
    cameraBtn.setOnClickListener {
        showDialog()
        pb.visibility = View.VISIBLE
        checkPermission(Manifest.permission.CAMERA,
            CAMERA_PERMISSION_CODE)
        startActivityForResult(receiptsViewModel.cameraIntent(requireActivity()),REQUEST_CODE_KAMERA)
    }

   fun showDialog() {
    val dialogBuilder = AlertDialog.Builder(context)
    dialogBuilder.setMessage("The message here")
    dialogBuilder.setPositiveButton("Done",
        DialogInterface.OnClickListener { dialog, whichButton -> })
    val b = dialogBuilder.create()
    b.show()
}
Run Code Online (Sandbox Code Playgroud)

jav*_*ero 5

您必须将您在 cameraBtn 上的内容实施到警报中

val dialogBuilder = AlertDialog.Builder(context)
    dialogBuilder.setMessage("The message here")
    
    dialogBuilder.setPositiveButton("Done"){dialogInterface, which ->  
        pb.visibility = View.VISIBLE
        checkPermission(Manifest.permission.CAMERA,CAMERA_PERMISSION_CODE)
        startActivityForResult(receiptsViewModel.cameraIntent(requireActivity()),REQUEST_CODE_KAMERA)
    }  

val b = dialogBuilder.create()
    b.show() 
Run Code Online (Sandbox Code Playgroud)