Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get high quality profile picture from GoogleSignInAccount

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 ?

like image 874
stackpic91 Avatar asked Apr 30 '16 14:04

stackpic91


2 Answers

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

like image 119
Bharatesh Avatar answered Nov 03 '22 06:11

Bharatesh


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

like image 43
Stanislav Kinzl Avatar answered Nov 03 '22 04:11

Stanislav Kinzl