0

我嘗試了谷歌登錄代碼片段,但不是將它放在一個活動上,而是將它用在一個片段上。它只適用於牛軋糖。這個問題似乎依賴於給予Google的意圖。只要我點擊Google登錄,它就會關閉我的應用。谷歌標誌不在低於牛軋糖的API上工作

該對話框顯示在我的應用程序外部,它不會回覆到我的片段。它只是關閉。

所以這是我的代碼:它幾乎與代碼片段相同。但這裏的問題是,當我點擊登錄Google時應用程序關閉時,它允許用戶每次選擇電子郵件,但它不會返回到onActivityResult,因爲我的logcat上沒有記錄的數據

public class LoginFragment extends Fragment implements OnConnectionFailedListener { 
    private FragmentManager fragmentManager; 
    private FragmentTransaction fragmentTransaction; 
    private Button signUp, login; 
    private View view; 
    private SharedPref pref; 


    private SignInButton signInButton; 
    private GoogleSignInOptions gso; 
    private GoogleApiClient mGoogleApiClient; 
    private int RC_SIGN_IN = 0; 
    private static final String TAG = "GPlusFragment"; 

    private Retrofit retrofit; 
    private RequestInterface requestInterface; 
    private ServerRequest request; 
    private boolean connectionError = false; 
    @Override 
    public void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
       .requestEmail() 
       .requestProfile() 
       .build(); 

     mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) 
       .enableAutoManage(getActivity() /* FragmentActivity */, this /* OnConnectionFailedListener */) 
       .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
       .build(); 
    } 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     view = inflater.inflate(R.layout.login_layout, container, false); 
     signUp = (Button) view.findViewById(R.id.signup); 
     login = (Button) view.findViewById(R.id.login); 
     fragmentManager = getFragmentManager(); 


     //Initializing signinbutton 
     signInButton = (SignInButton) view.findViewById(R.id.google_sign_in_button); 
     signInButton.setSize(SignInButton.SIZE_WIDE); 

     return view; 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 
     mGoogleApiClient.connect(); 
    } 

    @Override 
    public void onConnectionFailed(ConnectionResult connectionResult) { 
     mGoogleApiClient.stopAutoManage(getActivity()); 
     mGoogleApiClient.disconnect(); 
     connectionError = true; 
     signInButton.setVisibility(View.GONE); 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     mGoogleApiClient.connect(); 
    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
     //mGoogleApiClient.stopAutoManage(getActivity()); 
     mGoogleApiClient.disconnect(); 
    } 

    @Override 
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
     super.onViewCreated(view, savedInstanceState); 
     if (connectionError){ 
      mGoogleApiClient.stopAutoManage(getActivity()); 
      mGoogleApiClient.disconnect(); 
      signInButton.setVisibility(View.GONE); 
     } 
     signUp.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       fragmentTransaction = fragmentManager.beginTransaction().addToBackStack("signup").replace(R.id.content_view, new RegisterFragment()); 
       fragmentTransaction.commit(); 
      } 
     }); 
     login.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       fragmentTransaction = fragmentManager.beginTransaction().addToBackStack("signin").replace(R.id.content_view, new SignInFragment()); 
       fragmentTransaction.commit(); 
      } 
     }); 

     signInButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Auth.GoogleSignInApi.signOut(mGoogleApiClient); 
       Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
       startActivityForResult(signInIntent, RC_SIGN_IN); 
      } 
     }); 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     Log.d("It's here", "here"); 
     if (requestCode == RC_SIGN_IN) { 
       GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
       handleSignInResult(result); 
      } 
    } 

    private void handleSignInResult(GoogleSignInResult result) { 
     Log.d(TAG, "handleSignInResult:" + result.isSuccess()); 
     if (result.isSuccess()) { 
      //my code here doing the login 
      } 
    } 

    public void goToProfile(){ 
     Intent intent = new Intent(getContext(), HomeLoggedInActivity.class); 
     startActivity(intent); 
    } 
} 

回答

0

你必須使用的,而不是仿真器中的實際的Android手機,因爲它有一個老版本的谷歌的發揮

+0

那麼,有些人測試了它,並告訴谷歌登錄什麼都不做。 如果你想檢查應用程序本身:https://play.google.com/store/apps/details?id = com.infoman.ibenta –

1

的問題已通過刪除 的Android解決:在清單noHistory =「真」。這是防止用戶返回登錄活動的解決方案。

+0

如果你的問題已經解決,請將此標記爲答案 –

+0

我'兩天後會做。 –

相關問題