package com.flyingsoftgames.googleplayservices;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.games.Players;
import com.google.android.gms.games.Games;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.apache.cordova.PluginResult.Status;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.app.Activity;

import android.os.Bundle;
import org.apache.cordova.*;

public class GooglePlayServices extends CordovaPlugin implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
 
 private static final String LOGTAG = "GooglePlayServices";
 
 private GoogleApiClient mGoogleApiClient;
 
 @Override public void initialize (CordovaInterface cordova, CordovaWebView webView) {
  super.initialize (cordova, webView);
  boolean isGpsAvailable = (GooglePlayServicesUtil.isGooglePlayServicesAvailable(cordova.getActivity()) == ConnectionResult.SUCCESS);
  Log.w (LOGTAG, String.format("isGooglePlayServicesAvailable: %s",  isGpsAvailable ? "true" : "false"));
  if (!isGpsAvailable) return;
  Activity activity = cordova.getActivity();
  Context context   = activity.getApplicationContext();
  mGoogleApiClient = new GoogleApiClient.Builder (context)
   .addConnectionCallbacks (this)
   .addOnConnectionFailedListener (this)
   .addApi (Games.API)
   .addScope (Games.SCOPE_GAMES)
   .build ();
  mGoogleApiClient.connect ();
 }
 
 public void onConnectionFailed (ConnectionResult result) {
  if (!result.hasResolution()) return;
  Log.d (LOGTAG, result.toString());
  try {
   result.startResolutionForResult (cordova.getActivity(), result.SIGN_IN_REQUIRED);
  } catch (SendIntentException e) {
   // There was an error with the resolution intent. Try again.
   mGoogleApiClient.connect ();
  }
 }
 public void onConnected (Bundle connectionHint) {
  String playerId = Games.Players.getCurrentPlayerId (mGoogleApiClient);
  Log.w (LOGTAG, playerId);
 }
 public void onActivityResult (int requestCode, int responseCode, Intent intent) {
  if (!mGoogleApiClient.isConnecting()) mGoogleApiClient.connect ();
 }
 public void onConnectionSuspended (int cause) {mGoogleApiClient.connect ();}
 
 @Override public boolean execute (String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
  PluginResult result = null;
  String playerId = Games.Players.getCurrentPlayerId (mGoogleApiClient);
  if (action == "getPlayerId") result = new PluginResult(PluginResult.Status.OK, playerId);
  if (result != null) callbackContext.sendPluginResult (result);
  return true;
 }
}
@@ -2141,53 +2141,16 @@
 rn;%0A
-  Log.d (LOGTAG, result.toString());%0A
   try %7B%0A
    r
@@ -2145,16 +2145,16 @@
   try %7B%0A
+
    resul
@@ -2497,36 +2497,8 @@
 t);%0A
-  Log.w (LOGTAG, playerId);%0A
  %7D%0A 
@@ -2731,26 +2731,16 @@
  ();%7D%0A %0A
- @Override
  public 
@@ -2845,16 +2845,16 @@
 ption %7B%0A
+
   Plugin
@@ -2958,18 +2958,8 @@
 if (
-action == 
 %22get
@@ -2967,16 +2967,31 @@
 layerId%22
+.equals(action)
 ) result
@@ -3009,16 +3009,17 @@
 inResult
+ 
 (PluginR
@@ -3129,9 +3129,10 @@
 rue;%0A %7D%0A
-
 %7D
+%0A

Update GooglePlayServices.java