打开相机前显示对话框

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

现在用户单击一个按钮,消息显示 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()
}

回答

您必须将您在 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() 


以上是打开相机前显示对话框的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>