小编Piy*_*mar的帖子

Android 相机 Intent 在 OnePlus 设备中不起作用

我试图使用 Android 设备中预装的本机相机应用程序来为我的应用程序捕获图像。为此,我一直在使用这段代码:

当用户点击按钮时调用一个函数

take_img_btn.setOnClickListener {
    dispatchTakePictureIntent()
}
Run Code Online (Sandbox Code Playgroud)

该函数应该执行以下操作:

    private fun dispatchTakePictureIntent() {
        Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent ->
            // Ensure that there's a camera activity to handle the intent
            takePictureIntent.resolveActivity(packageManager)?.also {
                // Create the File where the photo should go
                val photoFile: File? = try {
                    createImageFile()
                } catch (ex: IOException) {
                    // Error occurred while creating the File
                    ex.printStackTrace()
                    null
                }
                // Continue only if the File was successfully created
                photoFile?.also {
                    val photoURI: Uri = FileProvider.getUriForFile(
                        this,
                        "com.example.android.fileprovider",
                        it …
Run Code Online (Sandbox Code Playgroud)

camera android kotlin

5
推荐指数
1
解决办法
3486
查看次数

标签 统计

android ×1

camera ×1

kotlin ×1