gpt4 book ai didi

android - 在Redmi 7A上启动相机拍照时应用程序崩溃

转载 作者:行者123 更新时间:2023-12-02 13:27:49 26 4
gpt4 key购买 nike

当我在 Redmi 7A 上启动相机拍照时,我的应用程序自动崩溃。以下是崩溃日志:

   E/CAM_CameraIntentManager: checkCallerLegality: Unknown caller: com.qikcircle.eclinic
请帮助它确实没有显示问题到底是什么。
我的 Activity 代码
class CaptureImageActivity : AppCompatActivity() {

private lateinit var mToolbar: Toolbar
private lateinit var mImage: ImageView
private var mBitmap: Bitmap? = null

private val getCameraAndStoragePermission = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
if (hasAllPermissionsGranted(permissions)) {
dispatchTakePictureIntent()
} else {
Toast.makeText(
this,
resources.getString(R.string.allow_camera_permission),
Toast.LENGTH_SHORT)
.show()
finish()
}
}

private val takePicture =
registerForActivityResult(ActivityResultContracts.TakePicture()) { success ->
if (success) {
photoURI.let {
mBitmap = getBitmap(this, photoURI)
mImage.setImageBitmap(mBitmap)
goBack()
}
} else {
Toast.makeText(
this,
resources.getString(R.string.something_went_wrong),
Toast.LENGTH_SHORT)
.show()
finish()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_capture_image)

setupToolbar()

mImage = findViewById(R.id.image)
val mSend = findViewById<ImageButton>(R.id.send)
mSend.setOnClickListener {
goBack()
}

checkCameraPermission()
}

private fun setupToolbar() {
mToolbar = findViewById(R.id.toolbar)
val title: TextView = findViewById(R.id.title)
title.text = resources.getString(R.string.app_name)
setSupportActionBar(mToolbar)
showBackButton()
}

private fun showBackButton() {
if (supportActionBar != null) {
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.setDisplayShowHomeEnabled(true)
}
mToolbar.setNavigationOnClickListener {
super.onBackPressed()
}
}

private fun checkCameraPermission() {
val permissions = arrayOf(
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
if (!hasPermissions(this, *permissions)) {
getCameraAndStoragePermission.launch(permissions)
return
}
dispatchTakePictureIntent()
}

private fun goBack() {
val intent = Intent()
intent.data = photoURI
setResult(Activity.RESULT_OK, intent)
finish()
}

private lateinit var currentPhotoPath: String

@Throws(IOException::class)
private fun createImageFile(): File {
// Create an image file name
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
val storageDir: File? = getExternalFilesDir(Environment.DIRECTORY_PICTURES)
return File.createTempFile(
"JPEG_${timeStamp}_", /* prefix */
".jpg", /* suffix */
storageDir /* directory */
).apply {
// Save a file: path for use with ACTION_VIEW intents
currentPhotoPath = absolutePath
}
}

private lateinit var photoURI: Uri

private fun dispatchTakePictureIntent() {
val photoFile: File? = try {
createImageFile()
} catch (ex: IOException) {
// Error occurred while creating the File
null
}
// Continue only if the File was successfully created
photoFile?.also {
photoURI = FileProvider.getUriForFile(
this,
"com.qikcircle.eclinic.fileprovider",
it
)
takePicture.launch(photoURI)
}
}
}
此外,应用程序并非每次都崩溃,而只是有时崩溃。

最佳答案

我的 Redmi Note 8t (MIUI Global 11.04.1) 也有同样的问题。但在 Redmi Note 8 Pro (MIUI Global 12.0.2) 上一切正常。看来这是小米MIUI的问题。一种解决方案是尝试安装其他 MIUI 或在没有任何外壳的情况下重新刷新 clear android。

关于android - 在Redmi 7A上启动相机拍照时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63191084/

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