【问题标题】:Profile pic from Firebase userprofile does not show up on real deviceFirebase 用户配置文件中的配置文件图片未显示在真实设备上
【发布时间】:2019-02-07 08:51:24
【问题描述】:

我正在使用 firebase 开发 android studio。我创建了登录和注册活动。用户还可以在那里更新个人资料图片和显示名称。 在检索用户个人资料时,我得到了显示名称、电子邮件、提供商、UID 和个人资料图片。

在模拟器中图像显示在图像视图中,但在实际运行时 设备图像未出现。

我还添加了 setPersistanceEnabled(true) 但它没有解决。我已经粘贴了创建和检索用户配置文件的代码。

   private void updateProfile(String uName, Uri uri) {
   UserProfileChangeRequest userProfileChangeRequest = new 
   UserProfileChangeRequest.Builder()
                .setDisplayName(uName)
                .setPhotoUri(uri)
                .build();
   user.updateProfile(userProfileChangeRequest);
   mRef.child("Name").setValue(uName);
   mRef.child(uri.getLastPathSegment()).setValue(uri.toString());
   StorageReference profileStorage = 
   mStorage.child(uri.getLastPathSegment());
        profileStorage.putFile(uri);
        showMessage("Upload Successful");
        Intent intent = new Intent(this,UserHome.class);
        startActivity(intent);
    }else{
        showMessage("Upload Profile Picture");
    }
    }


    ////// for retrieving and displaying ///////

    String namee = user.getDisplayName();
    Uri uri = mAuth.getCurrentUser().getPhotoUrl();        
    Glide.with(UserHome.this).load(uri).into(imageView);        
    textView.setText(user.getDisplayName());        
    Log.v("data",user.getPhotoUrl().toString());

【问题讨论】:

  • 您是否在 Firebase 控制台上提交了项目 sha 校验和?
  • 我只记得,firebase 控制台中的 SDK 设置说,运行您的应用程序以验证安装,永远不会完成
  • 我的应用程序已连接到 Firebase,但主要问题是图像根本没有显示在真实设备中。但是,在模拟器中,图像一旦上传就会显示,在模拟器中重新启动应用程序时,图像就会消失

标签: android firebase firebase-authentication


【解决方案1】:

当您从手机存储中选择图像后更新用户配置文件时,它会使用您手机的图像 URI 并使用它更新用户帐户。并且它在关闭或注销之前首先显示它,因为它仍在缓存中。但是,当您重新打开或登录该帐户时,缓存会被清除,并且不会显示该图像。因此,要解决此问题,您必须先将该图像上传到 Firebase 存储,然后获取该图像的链接并使用该链接更新当前用户的照片。这将是一个通用链接,即使在您重新打开应用或重新登录帐户后仍可使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 2014-11-01
    • 2015-07-30
    相关资源
    最近更新 更多