我已经使用以下代码:
RigidBodyPlant
还要使用此代码:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK && requestCode == PICTURE_RESULT) {
if (data != null) {
val imageUri: Uri = data.data!!
val ref: StorageReference = FirebaseUtil.storageRef!!.child(imageUri.lastPathSegment!!)
// Another implementation
// UploadTask uploadTask = ref.putFile(imageUrl)
ref.putFile(imageUri).addOnSuccessListener(this) {
ref.downloadUrl.addOnCompleteListener(this) { task ->
val url = task.result.toString()
deal!!.imageUrl = url
}
}
} else {
Log.d("IMAGE", resultCode.toString())
Toast.makeText(this, "Upload failure", Toast.LENGTH_LONG).show()
}
}
finish()
}
我可以从我的Android调试窗口中看到URI,但是未在firebase项中设置该URI,因为我正在使用最新的firebase最新数据库库。我可以在Android Studio的调试窗口中看到此值。 但是该值不用于设置我的Firebase条目的图像。我正在使用的库:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK && requestCode == PICTURE_RESULT )
{
if (data != null) {
val imageUri : Uri = data.data!!
val ref : StorageReference = FirebaseUtil.storageRef!!.child(imageUri.lastPathSegment!!)
// Another implementation
// UploadTask uploadTask = ref.putFile(imageUrl)
ref.putFile(imageUri).addOnSuccessListener(this, object : OnSuccessListener<UploadTask.TaskSnapshot> {
override fun onSuccess(taskSnapshot : UploadTask.TaskSnapshot?) {
val url : String = taskSnapshot!!.storage.downloadUrl.toString()
deal!!.imageUrl = url
}
})
} else {
Log.d("IMAGE", resultCode.toString())
Toast.makeText(this, "Upload failure", Toast.LENGTH_LONG).show()
}
}
}