我已经检查了可用资源,但是我得到了错误或者充其量还是得到了com.google.android.gms.tasks.zzu@5f9a842
作为uri
遵循此最新的google文档here,我仍然收到com.gms
作为网址
这是我的代码
val fileRef = storageProfilePicRef!!.child(firebaseUser.uid + "jpg")
val uploadTask = fileRef.putFile(imageUri!!)
uploadTask.continueWith {
if (!it.isSuccessful) {
pd.dismiss()
it.exception?.let { t ->
throw t
}
}
fileRef.downloadUrl
}.addOnCompleteListener {
if (it.isSuccessful) {
val downloadUrl = it.result
myUri = downloadUrl.toString()
print("Task: ${downloadUrl}")
...
Terminal: I/System.out: Task: com.google.android.gms.tasks.zzu@4298dc1(HTTPLog)-Static: isSBSettingEnabled false
请给我任何帮助,...
您输入了错误的值。代替这个:
print("Task: ${downloadUrl}")
登录此:
print("Task: ${downloadUrl.result.toString()}")
您的downloadUrl
变量未正确命名。这是一个任务,而不是URL。这样可能更清晰:
val task = it.result
val uri = task.result
val uriAsString = uri.toString()
已解决!!
val fileRef = storageProfilePicRef!!.child(firebaseUser.uid + "jpg")
val uploadTask = fileRef.putFile(imageUri!!)
uploadTask.continueWith {
if (!it.isSuccessful) {
pd.dismiss()
it.exception?.let { t ->
throw t
}
}
fileRef.downloadUrl
}.addOnCompleteListener {
if (it.isSuccessful) {
val downloadUrl = it.result //Here returns a task..
myUri = downloadUrl.toString()
print("Task: ${downloadUrl}")
...
[
val downloadurl = it.result
返回一个Task
通过添加addOnSuccessListener
进行更正
所以正确的代码是
val uploadTask = fileRef.putFile(imageUri!!)
uploadTask.continueWith {
if (!it.isSuccessful) {
pd.dismiss()
it.exception?.let { t ->
throw t
}
}
fileRef.downloadUrl
}.addOnCompleteListener {
if (it.isSuccessful) {
it.result!!.addOnSuccessListener{task ->
myUri = task.toString()
print("$myUri")
...
}