In my Android application in order to authenticate through the google account, I follow this official tutorial https://developers.google.com/identity/sign-in/android/people#retrieve_profile_information_for_a_signed-in_user and it works.
As stated there, to retrieve the profile picture I use "getPhotoUrl()" method of "GoogleSignInAccount" class. Example:
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount acct = result.getSignInAccount();
String personName = acct.getDisplayName();
String personEmail = acct.getEmail();
String personId = acct.getId();
Uri personPhoto = acct.getPhotoUrl();
The problem is that the image that I get through this URL is very poor quality (small size).
Screenshot example
How can I fix this problem ?
If your photo url has sz=50
key (image size 50 or something). Then replace size to the highest. like sz=240
I am not sure your photo url has sz
key because I used Person
API which has sz
key for getUrl()
to get user details which is now deprecated.
UPDATED: Person.Image - Official doc which says how to get different dimens of profile avatar
The URL of the person's profile photo. To resize the image and crop it to a square, append the query string ?sz=x, where x is the dimension in pixels of each side
However as @stackpic91 said new API GoogleSignInAccount.getPhotoUrl()
has S96-c
change its value to the highest to get large image S240-c
When loading the image with whatever loader you choose (Glide/Picasso), just do this to the url string:
avatarUrl.replace("s96-c", "s192-c", true)
or
avatarUrl.replace("s96-c", "s384-c", true)
for even better quality
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With