androidimagegoogle-play-servicesgoogle-play-gamesloading-image

Google play games user profile image not loading


Apologies for reposting the question but I get an error using this method and I can't figure out what I'm doing wrong.

  mPlayersClient = Games.getPlayersClient(this, googleSignInAccount);

    mPlayersClient.getCurrentPlayer()
            .addOnCompleteListener(new OnCompleteListener<Player>() {
                @Override
                public void onComplete(@NonNull Task<Player> task) {
                    String displayName;


                    Log.i("playerId" , task.getResult().getPlayerId());
                    if (task.isSuccessful()) {

                        displayName = task.getResult().getDisplayName();
                        Uri uri = task.getResult().getIconImageUri();
                        Log.i("url", uri.toString());

                        CircleImageView imageView = findViewById(R.id.testImage);
                        //ERROR : here when i use "this" it gets red underline
                        ImageManager manager = ImageManager.create(this);
                        manager.loadImage(imageView, uri, R.drawable.defualt_user_img);


                    }

The uri is of content scheme so I can't use Picasso. When I hover cursor over "this" it shows

Create (android.content.Context) in ImageManager cannot be applied to (anonymous com.google.android.gms.tasks.OnCompleteListener)


Solution

  • Don't use CircleImageView library i.e , implementation 'de.hdodenhof:circleimageview:2.2.0' . Apparently it doesn't support content scheme uri or play games don't support it, not sure which one is the case but it will work fine if you use android ImageView.

    Here is the final working code.

     ImageView imageView = findViewById(R.id.testImage);
     ImageManager manager = ImageManager.create(getApplicationContext());
     manager.loadImage(imageView,uri);