Code example for ConnectionResult

Methods: getErrorCode, hasResolution

0
	} 
 
	public void onConnectionFailed(ConnectionResult result) {
		// save connection result for later reference 
        mConnectionResult = result;
        debugLog("onConnectionFailed: result " + result.getErrorCode());
        if(result.hasResolution())
        	resolveConnectionResult(); 
        else 
        	UnityPlayer.UnitySendMessage(TAG, "GPGAuthResult", "error");
	} 
 
	public void onConnected(Bundle connectionHint) {
		debugLog("onConnected: connected! client=" + mClientCurrentlyConnecting);
 
        // Mark the current client as connected 
        mConnectedClients |= mClientCurrentlyConnecting;
 
        // If this was the games client and it came with an invite, store it for 
        // later retrieval. 
        if (mClientCurrentlyConnecting == CLIENT_GAMES && connectionHint != null) {
            debugLog("onConnected: connection hint provided. Checking for invite."); 
            Invitation inv = connectionHint.getParcelable(GamesClient.EXTRA_INVITATION);
            if (inv != null && inv.getInvitationId() != null) {
                // accept invitation 
                debugLog("onConnected: connection hint has a room invite!"); 
                mInvitationId = inv.getInvitationId();
                debugLog("Invitation ID: " + mInvitationId);
            } 
        } 
 
        // connect the next client in line, if any. 
        connectNextClient(); 
		 
	} 
 
	public void onDisconnected() { 
		debugLog("onDisconnected."); 
        mConnectionResult = null;
        mAutoSignIn = false;
        mSignedIn = false;
        mSignInError = false;
        mInvitationId = null;
        mConnectedClients = CLIENT_NONE;
        UnitySendMessageSafe("GPGAuthResult", "signedout"); 
	} 
	 
	/** 
     * Handle activity result. Call this method from your Activity's 
     * onActivityResult callback. If the activity result pertains to the sign-in 
     * process, processes it appropriately. 
     */ 
    public void onActivityResult(int requestCode, int responseCode, Intent intent) {
        if (requestCode == RC_RESOLVE) {
            // We're coming back from an activity that was launched to resolve a 
            // connection 
            // problem. For example, the sign-in UI. 
            mExpectingActivityResult = false;
            debugLog("onActivityResult, req " + requestCode + " response " + responseCode);
            if (responseCode == Activity.RESULT_OK) {
                // Ready to try to connect again. 
                debugLog("responseCode == RESULT_OK. So connecting."); 
                connectCurrentClient(); 
            } else { 
                // Whatever the problem we were trying to solve, it was not 
                // solved. 
                // So give up and show an error message. 
                debugLog("responseCode != RESULT_OK, so not reconnecting."); 
                giveUp(); 
            } 
        } 
    } 
     
    void resolveConnectionResult() { 
        // Try to resolve the problem 
        debugLog("resolveConnectionResult: trying to resolve result: " + mConnectionResult);
        if (mConnectionResult.hasResolution()) {
            // This problem can be fixed. So let's try to fix it. 
            debugLog("result has resolution. Starting it."); 
            try { 
                // launch appropriate UI flow (which might, for example, be the 
                // sign-in flow) 
                mExpectingActivityResult = true;
                debugLog("Resolving intent with activity "+mParentActivity);
                // create dummy activity 
                /*mDummyActivity = new DummyActivity(); 
                Intent intent = new Intent(); 
                mDummyActivity.startActivity(intent);*/ 
                 
                Intent intent = new Intent(mParentActivity, DummyActivity.class);
    			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    			//mParentActivity.startActivity(intent); 
    			mParentActivity.startActivityForResult(intent, RC_UNUSED);
    			 
//                mConnectionResult.startResolutionForResult(mParentActivity, RC_RESOLVE); 
                //PendingIntent intent = mConnectionResult.getResolution(); 
//                mParentActivity.startActivityForResult((Intent)intent, RC_RESOLVE); 
            } catch (Exception e) {
                // Try connecting again 
                debugLog("SendIntentException."); 
                connectCurrentClient(); 
            } 
        } else { 
            // It's not a problem what we can solve, so give up and show an 
            // error. 
            debugLog("resolveConnectionResult: result has no resolution. Giving up."); 
            giveUp(); 
        } 
    } 
 
     
    void giveUp() { 
        mSignInError = true;
        mAutoSignIn = false;
        debugLog("giveUp: giving up on connection. " + 
                ((mConnectionResult == null) ? "(no connection result)" :
                        ("Status code: " + mConnectionResult.getErrorCode())));
 
        if (mConnectionResult != null) {
            UnitySendMessageSafe("GPGAuthResult", "error,"+mConnectionResult.getErrorCode());
        } else { 
            // this is a bug 
            Log.e("GameHelper", "giveUp() called with no mConnectionResult");
            UnitySendMessageSafe("GPGAuthResult", "error"); 
        }