2013-10-02 18 views
0

即時通訊嘗試使用google pluse自動登錄。PlusClient onConnected沒有觸發

我使用SignInButton按鈕小部件。

當我點擊日誌中我看到進度對話框,但onConnected是沒有得到triggred

這是我BUTTOM按代碼:

case R.id.sign_in_button: 
     { 
      if(!mPlusClient.isConnected()) 
      { 
       if (mConnectionResult == null) { 
        { 
         pDialog = new ProgressDialog(RegisterPage.this); 
         pDialog.setMessage("logging in..."); 
         pDialog.setIndeterminate(false); 
         pDialog.setCancelable(true); 
         pDialog.show(); 
        } 
       } else { 
        try { 
         mConnectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR); 
        } catch (SendIntentException e) { 
         // Try connecting again. 
         mConnectionResult = null; 
         mPlusClient.connect(); 
        } 
       } 

      break; 
     } 

我onConnected代碼:

@Override 
    public void onConnected(Bundle arg0) { 
     // TODO Auto-generated method stub 
     Log.i("ok", "ok"); 

     if (mPlusClient.getCurrentPerson() != null && isNetworkAvailable()) 
      new GooglePlusRegister().execute(); 
     else 
     { 
      if(pDialog != null) 
       pDialog.dismiss(); 

      Toast.makeText(getApplicationContext(),"No internet connection", Toast.LENGTH_SHORT).show(); 
     } 
    } 

的進度對話框不dissarityng,我沒有看到我的日誌調用。

在我的onCreate

mPlusClient = new PlusClient.Builder(this, this , this).setScopes(Scopes.PLUS_LOGIN).setVisibleActivities("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity").build(); 

進口:再次

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks; 
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener; 
import com.google.android.gms.common.Scopes; 
import com.google.android.gms.common.SignInButton; 
import com.google.android.gms.plus.PlusClient; 
import com.google.android.gms.plus.model.people.Person; 

回答

2

看看你的代碼:mPlusClient.connect()永遠不會被執行。

條件語句if (mConnectionResult == null)只顯示ProgressDialog而沒有實際連接到Google Plus。

我不得不查看處理錯誤情況的正確方法,但是從我的頭頂開始,只需刪除else語句的行即可解決您的問題。

+0

我現在看到它,謝謝。 – dasdasd