我正在使用Fresco lib在Kotlin上拍照,并且我需要使用拍照的照片通过JSON API发送照片。 问题是
android.provider.MediaStore.Images.ImageColumns.DATA
被标记为已弃用。
private fun processCapturedPhoto() {
try{
val cursor = contentResolver.query(
Uri.parse(mCurrentPhotoPath),
Array(1) {
android.provider.MediaStore.Images.ImageColumns.DATA
},
null, null, null)
cursor?.moveToFirst()
val photoPath = cursor?.getString(0)
cursor?.close()
val file = File(photoPath ?: "")
val uri = Uri.fromFile(file)
val height = resources.getDimensionPixelSize(R.dimen.photo_height)
val width = resources.getDimensionPixelSize(R.dimen.photo_width)
val request = ImageRequestBuilder.newBuilderWithSource(uri)
.setResizeOptions(ResizeOptions(width, height))
.build()
val controller = Fresco.newDraweeControllerBuilder()
.setOldController(cameraView?.controller)
.setImageRequest(request)
.build()
cameraView?.controller = controller
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this@GrabarFichajeViewController.oFichajeTestGrabacion.rutaFoto = String(Base64.getEncoder().encode(file.readBytes()))
this.hacerFoto = false
}
if(grabarFichajeTrasFoto){
this.procesarGrabado()
}
}
catch (ex: Exception){
Log.e("processCapturedPhotoEX", ex.toString() + "-" + ex.message)
}
}
我正在跟踪此链接拍照https://medium.com/@bionicwan/android-how-to-take-a-photo-using-kotlin-6ce7f0dee9c8
谢谢。