2016-05-12 259 views
0

我正在Android上開發應用程序,並且希望允許用戶使用其Google帳戶登錄。我管理登錄,但我有註銷問題。最後,我有一個帶有註銷選項的導航抽屜。有人可以幫我實現註銷嗎?Google帳戶登錄和註銷

我試過https://developers.google.com/identity/sign-in/android/disconnect的代碼,但沒有奏效。

LogoutFragment

public class LogoutFragment extends Fragment { 
private GoogleApiClient mGoogleApiClient; 

private TextView mStatusTextView; 
private ProgressDialog mProgressDialog; 


public LogoutFragment() { 
    // Required empty public constructor 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 

    signOut(); 
    return inflater.inflate(R.layout.fragment_logout, container, false); 
} 

public void signOut() { 
    Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
      new ResultCallback<Status>() { 
       @Override 
       public void onResult(Status status) { 
        // [START_EXCLUDE] 
        updateUI(false); 
        // [END_EXCLUDE] 
       } 
      }); 
} 
} 
+0

發佈您的代碼。你有沒有嘗試過'Logout'? –

+0

郵政編碼或即將發佈的信息將被刪除。 –

+0

@jaydroider添加了我的代碼.. – PersianBlue

回答

0

首先,你必須初始化與建築商的mGoogleApiClient,然後將它傳遞給註銷方法。

入住此示例代碼: Click

+0

我很新的android。你能幫我編碼嗎? – PersianBlue

+0

只需查看我鏈接到的示例代碼,即可瞭解如何構建您的GoogleApiClient以及如何登錄和註銷。 – Seishin

+0

但我有一個導航抽屜,並且示例代碼說要製作註銷按鈕。如何將其更改爲在導出抽屜中單擊「註銷」 – PersianBlue