android - 更新用户个人资料照片不会使用 currentUser.photoUrl 进行更新

标签 android firebase kotlin google-cloud-firestore firebase-authentication

我拍了一张照片,然后更新我当前的用户照片以将此更改应用到经过 Firebase 身份验证的用户。

我所期望的是在将这张照片更新给经过身份验证的用户后,将 photoUrl 作为字符串获取,就像我第一次登录我的应用程序时一样

suspend fun updatePhoto(uri: Uri): Resource<Unit>{
        val currentUser = FirebaseAuth.getInstance().currentUser
        val profileUpdates = UserProfileChangeRequest.Builder().setPhotoUri(uri).build()
        currentUser!!.updateProfile(profileUpdates).await()
        currentUser.reload().await()
        val userData = hashMapOf<String,Any>()
        userData["photoUrl"] = currentUser.photoUrl.toString()
        FirebaseFirestore
            .getInstance()
            .collection("user")
            .document(currentUser.uid).set(userData, SetOptions.merge()).await()
        return Resource.Success(Unit)
    }

在这一行 userData["photoUrl"] = currentUser.photoUrl.toString() 我希望实际的 photoUrl 在 firebase 中更新,并且我得到一个本地 Uri,如 file://my.com.app/cache/photo.jpg

如果我通过身份验证本身更新了用户照片,Firebase 是否不会处理更新后的照片并需要返回当前用户更新的实际照片?

我想避免使用 Firebase 存储来上传照片并将其放入数据库中,而是想直接从更新的用户照片中检索它

最佳答案

当您设置 Firebase Auth 用户照片网址时,它不会获取该图像的内容并存储它。您可能从应用程序的另一部分传递了该文件 URL,现在它返回了与预期相同的字符串。

我认为没有任何方法可以避免将该图像上传到可以为您托管图像的服务,例如 Cloud Storage。

关于android - 更新用户个人资料照片不会使用 currentUser.photoUrl 进行更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60908489/

相关文章:

ios - Firebase:如何检查用户的手机是否已验证并自动登录?

android - com.app.MainActivity 无法转换为 com.facebook.react.ReactActivity

android - 如何在 ListView 项目的 View 上添加不同的 OnClickListeners 以执行不同的操作

android - 现在有人知道如何注册 Google Backup API key 吗?

java - 无法检索列表 firebase

kotlin - @JvmDefault 以及如何添加编译器选项

android - 无法使用 ViewModelFactory 实例化我的 ViewModel

java - Android:为什么我不能在新线程中创建处理程序

android - 我不明白 MVVM 上的 "instance has not been initialized"

android - 为什么我收到 AbstractDynamicObject$CustomMessageMissingMethodException 错误?