使用相机的意图,我可以毫无问题地捕获照片并将结果保存到图库。但是,当我在图库应用程序中检查它们时,我的所有图像都没有缩略图。因此,我想我也需要保存缩略图(不仅仅是全尺寸的图像。)。如果这个假设是正确的,那么我该如何存储缩略图,以便android画廊应用知道这些缩略图是用于我的图像的,因此它们将在画廊视图中显示。如果有帮助,以下是我的代码的摘录:
override fun onActivityResult(requestCode: Int, resultCode: Int, responseData: Intent?) {
when (requestCode) {
PERMISSION_CAMERA -> if (resultCode == RESULT_OK) {
AddPicToGallery()
}
}
}
private fun AddPicToGallery() {
Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE).also { mediaScanIntent ->
val f = File(currentPhotoPath)
mediaScanIntent.data = Uri.fromFile(f)
sendBroadcast(mediaScanIntent)
createImage(title!!, currentPhotoPath)
}
}
private fun dispatchTakePictureIntent() {
Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent ->
takePictureIntent.resolveActivity(packageManager)?.also {
val photoFile: File? = try {
createImageFile()
} catch (ex: IOException) {
null
}
photoFile?.also {
val photoURI: Uri = FileProvider.getUriForFile(
this,
"com.example.android.fileprovider",
it
)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
startActivityForResult(takePictureIntent, PERMISSION_CAMERA)
}
}
}
}
targetSdkVersion 28 设备-s6