Java 如何将gmail中的图片显示到应用程序的导航视图中?
我正在尝试使用Glide库,为此我添加了依赖项: 。 我的姓名和电子邮件已成功显示,但我的照片未成功显示。 以下是代码片段:Java 如何将gmail中的图片显示到应用程序的导航视图中?,java,android,imageview,android-glide,google-authentication,Java,Android,Imageview,Android Glide,Google Authentication,我正在尝试使用Glide库,为此我添加了依赖项: 。 我的姓名和电子邮件已成功显示,但我的照片未成功显示。 以下是代码片段: //controls View headerView = navigationView.getHeaderView(0); tvUserName = headerView.findViewById(R.id.tvGoogleName); tvEmail = headerView.findViewById(R.id.tvEmail); im
//controls
View headerView = navigationView.getHeaderView(0);
tvUserName = headerView.findViewById(R.id.tvGoogleName);
tvEmail = headerView.findViewById(R.id.tvEmail);
imgProfile = headerView.findViewById(R.id.imgProfile);
//google
GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(this);
if(acct != null){
String userName = acct.getDisplayName();
String email = acct.getEmail();
Uri photo = acct.getPhotoUrl();
if(photo != null){
Toast.makeText(this, "photo is not null", Toast.LENGTH_SHORT).show(); // true
}
else{
Toast.makeText(this, "photo is null", Toast.LENGTH_SHORT).show();
}
tvUserName.setText(userName);
tvEmail.setText(email);
Glide.with(this).load(String.valueOf(photo)).into(imgProfile);
}
符合
返回已登录用户的照片url,如果该用户有配置文件图片,并且您从新的GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_in)}或配置了GoogleSignInOptions.Builder.requestProfile()构建了配置;否则为空即使在配置时,也不能保证所有用户都能使用。
您能否验证是否从getPhotoUrl获取了有效的URL?在我重新安装应用程序时,它起到了作用。我在登录后在我的帐户上添加了图片。谢谢你的回答:)
public Uri getPhotoUrl ()