Firebase用户图像到ImageView

时间:2017-04-17 20:59:04

标签: android firebase imageview firebase-authentication

我正在开发Android Studio,试图将我从使用Google登录获得的FirebaseUser中的图像显示为图像视图。

private void setUserData(FirebaseUser user) {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    View cabecera = navigationView.getHeaderView(0);

    TextView titulo = (TextView) cabecera.findViewById(R.id.titulo_cabecera);
    titulo.setText(user.getDisplayName());

    TextView mail = (TextView) cabecera.findViewById(R.id.mail_cabecera);
    mail.setText(user.getEmail());

    ImageView foto = (ImageView) cabecera.findViewById(R.id.imagen_cabecera);
    foto.setImageURI(user.getPhotoUrl());

}

两个文本视图都正确显示,但是当我进入imageview时,我收到此错误:

  

E / BitmapFactory:无法解码流:java.io.FileNotFoundException:https:/lh3.googleusercontent.com/-DWsn6ecRPm0/AAAAAAAAAAI/AAAAAAAAAGk/K9bdBjTZO0Y/s96-c/photo.jpg:open failed:ENOENT(No这样的文件或目录)

     

I / System.out:resolveUri在坏位图uri上失败:https://lh3.googleusercontent.com/-DWsn6ecRPm0/AAAAAAAAAAI/AAAAAAAAAGk/K9bdBjTZO0Y/s96-c/photo.jpg

并且在imageview上没有显示任何内容,如果我使用chrome链接显示图像,是否有我遗漏或做错的事情?

1 个答案:

答案 0 :(得分:2)

要从网络加载图片,请尝试使用此库http://square.github.io/picasso/

这是一个例子:

uses
  System.Json;

procedure TForm1.Button1Click(Sender: TObject);
var
 jsonText: string;
 jsonArray: TJsonArray;
 dataObj: TJsonObject;
 Jobj: TJsonObject;
 krsPodmiotyNazwaOrganuReprezentacjiValue: TJsonValue;
 krsPodmiotyDotacjeUeBeneficjentIdValue: TJsonValue;
 krsPodmiotyLiczbaProkurentowValue: TJsonValue;
begin
 jsonText := '[{Your JSON content here}]';
 Jobj := TJSONObject.ParseJSONValue(jsonText) as TJsonObject;
 jsonArray :=Jobj.GetValue('Dataobject') as TJsonArray;
 dataObj := (jsonArray.Items[0] as TJsonObject).GetValue('data') as  TJsonObject;
  krsPodmiotyNazwaOrganuReprezentacjiValue := dataObj.GetValue('krs_podmioty.nazwa_organu_reprezentacji');
  krsPodmiotyDotacjeUeBeneficjentIdValue := dataObj.GetValue('krs_podmioty.dotacje_ue_beneficjent_id');
  krsPodmiotyLiczbaProkurentowValue := dataObj.GetValue('krs_podmioty.liczba_prokurentow');
  MessageDlg(krsPodmiotyNazwaOrganuReprezentacjiValue.Value, mtInformation, [mbOK], 0, mbOK);
  MessageDlg(krsPodmiotyDotacjeUeBeneficjentIdValue.Value, mtInformation, [mbOK], 0, mbOK);
  MessageDlg(krsPodmiotyLiczbaProkurentowValue.Value, mtInformation, [mbOK], 0, mbOK);
end;