1

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)

notakoba
  • 160
  • 1
  • 13
  • It would help if you told us what error you were getting, – Scott Cooper Sep 06 '18 at 11:47
  • @ScottCooper , I get no error in logs as i can't run the code, because when when I do `ImageManager manager = ImageManager.create(this);` , "this" get red underlined – notakoba Sep 06 '18 at 11:50
  • @ScottCooper I updated the question with more info. I hope it is more clear now. – notakoba Sep 06 '18 at 12:52
  • Could you provide the logs? – abielita Sep 06 '18 at 13:34
  • @abielita when I run app it throws error -error: incompatible types: > cannot be converted to Context . I tried to declare imageManager as a member class and initialize it onCreate , doing so i was able to fill imageView with the placeholder image but still no luck in loading uri – notakoba Sep 06 '18 at 14:09
  • 1
    You need to provide a context object. If this is running in an activity, you can do so by referencing the outer class with something like `ImageManager manager = ImageManager.create(OuterActivity.this);` – Caleb_Allen Sep 06 '18 at 15:56
  • @Caleb_Allen Yes, I'm running this under an Activity and I already tried `ActivityName.this`, it doesn't throw any error nor it loads Uri or the placeholder Image. I also tried `getBaseContext()`, `getApplicationContext()` . and same thing happens. No error, No loading of the image. However when I declared imageManager as a member class and initialized it `onCreate` it was at least loading placeholder. So, I wonder if `ImageManager` is the right way to load content scheme uri or not. – notakoba Sep 07 '18 at 07:17

1 Answers1

1

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);
notakoba
  • 160
  • 1
  • 13