Matt
Matt

Reputation: 3912

Initiating the Play Services GamesClient

I am having trouble creating the GamesClient for the new Google Play Services. I have tried both what the poster and the one who gave the answer here with no success. I have followed all of the docs on setting up the Play Services (more specifically the leaderboard) but I feel as if they have no section in any of their docs on where and how to set up the GamesClient. Maybe I am wrong and please link me if I am.

Right now I have the below code in my onCreate() but with errors.

GamesClient mGamesClient;
mGamesClient = new GamesClient(null, null, null, null, null, null, 0, null);
mGamesClient.connect();

//Error:  "The constructor GamesClient(Context, String, String, GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener, String[], int, View) is not visible.

I also tried this code with no success:

GamesClient client = GamesClient.Builder(this, this, this).create();

//Error:  "The method Builder(MainMenu, MainMenu, MainMenu) is undefined for the type GamesClient."

Can someone provide me with help on how to instantiate this GamesClient?

Upvotes: 0

Views: 659

Answers (2)

user2161301
user2161301

Reputation: 824

I don't really think the answer above helps you. I struggled with your problem for hours and now I got the solution. You are doing the Builder in a wrong way, you gotta create an object of it (the documentation lacks terribly..)

mGamesClient = new GamesClient.Builder(getBaseContext(), this, this)
             .create();         
                mGamesClient.connect();

I hope it helps

Upvotes: 0

Bryan Herbst
Bryan Herbst

Reputation: 67189

Your MainMenu class that you are passing in to the GamesClient.Builder constructor as "this" needs to:

  • Be a Context
  • Implement GooglePlayServicesClient.ConnectionCallbacks
  • Implement GooglePlayServicesClient.OnConnectionFailedListener

I'm guessing that the class currently fails one or more of those requirements. For more information on the GamesClient.Builder, check out the documentation.

Upvotes: 4

Related Questions