Я открываю камеру с kotlin
, как показано ниже:
private fun dispatchTakePictureIntent() {
Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent ->
// Create the File where the photo should go
val photoFile: File? = try {
activity?.createImageFile()
} catch (ex: IOException) {
Timber.e(ex)
null
}
// Continue only if the File was successfully created
photoFile?.also {
takenPhotoUri = FileProvider.getUriForFile(
requireContext(), "zz.zz.android.fileprovider", it
)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, takenPhotoUri)
startActivityForResult(takePictureIntent, REQUEST_CODE_FOR_PERFORM_CAMERA)
}
}
}
Но поймите меня ниже, ошибка:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.sec.android.app.camera/.Camera launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } clip={text/uri-list U:content://zz.zz.android.fileprovider/zz_zz_chat_images/PNG_%DB%B2%DB%B0%DB%B1%DB%B9%DB%B0%DB%B1%DB%B1%DB%B4_%DB%B1%DB%B4%DB%B2%DB%B2%DB%B5%DB%B5_1904526976.png} (has extras) } from ProcessRecord{e956b7f 13929:zz.zz.android.dev/u0a1605} (pid=13929, uid=11605) with revoked permission android.permission.CAMERA
Я использую с intent
для открытой камеры.
А вот и мой onActivityResult
:
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
if (resultCode == Activity.RESULT_OK) {
when (requestCode) {
REQUEST_CODE_FOR_PERFORM_CAMERA -> takenPhotoUri?.let { uri ->
uri.getBitmpap(requireContext())?.let { bitmap ->
presenter.uploadImage(chatRoomId, "image/png", uri, bitmap, "")
}
}
}}