0

Google 드라이브의 앱 폴더에 글을 쓰는 SyncAdapter (코드는 UI 스레드에서 실행되지 않습니다)가 있습니다. Google 로그인을 사용하지 않고 GoogleApiClient을 사용해도 정상적으로 작동했지만 Google 로그인으로 GoogleApiClient으로 이동하려고합니다.GOOGLE_SIGN_IN_API에서 GoogleApiClient.blockingConnect()가 작동하지 않습니다.

없는 작업 코드 구글 로그인에서 :

mGoogleApiClient = new GoogleApiClient.Builder(context) 
      .setAccountName(accountName) 
      .addApi(Drive.API) 
      .addScope(Drive.SCOPE_APPFOLDER) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .build(); 
    mGoogleApiClient.blockingConnect(); 

을 지금은 구글이 서명에 더 이상 작동 사용하여 이동 한 것이다.

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
      .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)) 
      .build(); 
    mGoogleApiClient = new GoogleApiClient.Builder(mApplication) 
      .addApi(Drive.API) 
      .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
      .addConnectionCallbacks(this) 
      .addOnConnectionFailedListener(this) 
      .build(); 
    mGoogleApiClient.blockingConnect(); 

내 프로그램이 blockingConnect()에 호출에 다음과 같은 오류로 쓰러져서 :

java.lang.IllegalStateException: Cannot use SIGN_IN_MODE_REQUIRED with GOOGLE_SIGN_IN_API. Use connect(SIGN_IN_MODE_OPTIONAL) instead. 

가 구글과 함께 blockingConnect()을 수행하는 방법은 다음 코드는 내가 사용하려고 것입니다 로그인 API?

SyncAdapter이 위의 코드를 시도하기 전에 UI 스레드에서 초기 로그인을 수행합니다.

+0

내가 ... 내가 플레이 서비스 9.4을 사용하고 추가하는 것을 잊었다. 0 –

답변

0

이 내가 API 내 SyncAdapter에서 작동시킬 수있는 유일한 방법입니다 - 새로운 API는 blockingConnect() 작업을 거부 :

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
      .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)) 
      .build(); 
    mGoogleApiClient = new GoogleApiClient.Builder(mApplication) 
      .addApi(Drive.API) 
      .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
      .build(); 
    long start = System.currentTimeMillis(); 
    mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL); 
    while (mGoogleApiClient.isConnecting() && System.currentTimeMillis() - start < 5000) { 
     try { 
      Thread.sleep(250, 0); 
     } catch (InterruptedException e) { 
     } 
    } 
    if (mGoogleApiClient.isConnected()) { 
     try { 
      // Do stuff with Google Drive. 
     } finally { 
      mGoogleApiClient.disconnect(); 
     } 
    }