如何将图像作为帖子发布,Kotlin+;火库
我正在制作一个小型社交网络类型的应用程序,用户输入文本和图像,然后将它们显示在主屏幕上。我已经完成了文本的一部分,但现在我缺少图像。我已经做了打开图库的功能,用户可以选择一个图像并反映他们选择的图像 这是我用来打开设备库并选择其中一个的功能: 画廊就在这里开门如何将图像作为帖子发布,Kotlin+;火库,kotlin,google-cloud-firestore,Kotlin,Google Cloud Firestore,我正在制作一个小型社交网络类型的应用程序,用户输入文本和图像,然后将它们显示在主屏幕上。我已经完成了文本的一部分,但现在我缺少图像。我已经做了打开图库的功能,用户可以选择一个图像并反映他们选择的图像 这是我用来打开设备库并选择其中一个的功能: 画廊就在这里开门 object imageController { fun selectPhotoFromGallery(activity: Activity, code: Int ) { val intent = Intent(I
object imageController {
fun selectPhotoFromGallery(activity: Activity, code: Int ) {
val intent = Intent(Intent.ACTION_PICK)
intent.type = "image/*"
activity.startActivityForResult(intent, code)
}
fun saveImage(context: Context, id : Long, uri: Uri) {
val file = File(context.filesDir, id.toString())
val bytes = context.contentResolver.openInputStream(uri)?.readBytes()!!
file.writeBytes(bytes)
}
}
以下是用户选择的图像:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when {
requestCode == SELECT_ACTIVITY && resultCode == Activity.RESULT_OK -> {
imageUri = data!!.data
imageView32.setImageURI(imageUri)
}
}
}
现在我只想将图像保存在firestore中的文档中,并最终在帖子中显示图像
firestore文档中的文本如下所示:
holder.layout.name_service.text = post.service
如何获得图像?您不想这样做。你应该退房。你可以用这个。它就是为存储媒体文件而设计的。这是更现实的 你可以跳到如何开始的部分。您将获得更多信息