0

내 Android 앱에서 google + 로그인을 사용하고 있습니다. google + 로그인이 작동하지만 내 맞춤 홈페이지를 탐색하고 싶습니다. 내 Google + 로그인 코드는 MainActivity.java에 있습니다.활동 내 Google + 로그인에서 내 맞춤 홈페이지로 이동

로그인 후 내 홈페이지 (예 : Main_tab.java)로 이동하려면 어떻게해야합니까? 여기

은 내 코드입니다 MainActivity

public class MainActivity extends AppCompatActivity implements 
    GoogleApiClient.OnConnectionFailedListener, View.OnClickListener { 

private static final String TAG = "SignInActivity"; 
private static final int RC_SIGN_IN = 9001; 

private GoogleApiClient mGoogleApiClient; 
private TextView mStatusTextView; 
private ProgressDialog mProgressDialog; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // Views 
    mStatusTextView = (TextView) findViewById(R.id.status); 

    // Button listeners 
    findViewById(R.id.sign_in_button).setOnClickListener(this); 
    findViewById(R.id.sign_out_button).setOnClickListener(this); 
    findViewById(R.id.disconnect_button).setOnClickListener(this); 

    // [START configure_signin] 
    // Configure sign-in to request the user's ID, email address, and basic 
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN. 
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
      .requestEmail() 
      .build(); 
    // [END configure_signin] 

    // [START build_client] 
    // Build a GoogleApiClient with access to the Google Sign-In API and the 
    // options specified by gso. 
    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) 
      .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
      .build(); 
    // [END build_client] 

    // [START customize_button] 
    // Set the dimensions of the sign-in button. 
    SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button); 
    signInButton.setSize(SignInButton.SIZE_STANDARD); 
    // [END customize_button] 
} 

@Override 
public void onStart() { 
    super.onStart(); 

    OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient); 
    if (opr.isDone()) { 
     // If the user's cached credentials are valid, the OptionalPendingResult will be "done" 
     // and the GoogleSignInResult will be available instantly. 
     Log.d(TAG, "Got cached sign-in"); 
     GoogleSignInResult result = opr.get(); 
     handleSignInResult(result); 
    } else { 
     // If the user has not previously signed in on this device or the sign-in has expired, 
     // this asynchronous branch will attempt to sign in the user silently. Cross-device 
     // single sign-on will occur in this branch. 
     showProgressDialog(); 
     opr.setResultCallback(new ResultCallback<GoogleSignInResult>() { 
      @Override 
      public void onResult(GoogleSignInResult googleSignInResult) { 
       hideProgressDialog(); 
       handleSignInResult(googleSignInResult); 
      } 
     }); 
    } 
} 

// [START onActivityResult] 
@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); 
    if (requestCode == RC_SIGN_IN) { 


    } 
     GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
     handleSignInResult(result); 
    } 

// [END onActivityResult] 

// [START handleSignInResult] 
private void handleSignInResult(GoogleSignInResult result) { 
    Log.d(TAG, "handleSignInResult:" + result.isSuccess()); 
    if (result.isSuccess()) { 
     // Signed in successfully, show authenticated UI. 

     GoogleSignInAccount acct = result.getSignInAccount(); 
     mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName())); 
     updateUI(true); 
    } else { 
     // Signed out, show unauthenticated UI. 
     updateUI(false); 
    } 
} 
// [END handleSignInResult] 

// [START signIn] 
private void signIn() { 

    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
    startActivityForResult(signInIntent, RC_SIGN_IN); 
} 
// [END signIn] 

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

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

@Override 
public void onConnectionFailed(ConnectionResult connectionResult) { 
    // An unresolvable error has occurred and Google APIs (including Sign-In) will not 
    // be available. 
    Log.d(TAG, "onConnectionFailed:" + connectionResult); 
} 

private void showProgressDialog() { 
    if (mProgressDialog == null) { 
     mProgressDialog = new ProgressDialog(this); 
     mProgressDialog.setMessage(getString(R.string.loading)); 
     mProgressDialog.setIndeterminate(true); 
    } 

    mProgressDialog.show(); 
} 

private void hideProgressDialog() { 
    if (mProgressDialog != null && mProgressDialog.isShowing()) { 
     mProgressDialog.hide(); 
    } 
} 

private void updateUI(boolean signedIn) { 
    if (signedIn) { 
     findViewById(R.id.sign_in_button).setVisibility(View.GONE); 
     findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE); 
    } else { 
     mStatusTextView.setText(R.string.signed_out); 

     findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE); 
     findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE); 
    } 
} 

@Override 
public void onClick(View v) { 
    switch (v.getId()) { 
     case R.id.sign_in_button: 
      signIn(); 
      break; 
     case R.id.sign_out_button: 
      signOut(); 
      break; 
     case R.id.disconnect_button: 
      revokeAccess(); 
      break; 
    } 
} 
} 

답변

0

기호 성공 경우, 안드로이드의 의도와 기본 개념 경우에 대해 알아 Explicit intent from Android doc 코드와 Vogella tutorials

를 사용하여 원하는 활동을 엽니 다 당신은 모릅니다, 그들이 기본이기 때문에 그것은 당신을 도울 것입니다.

+0

_ 외부 리소스에 대한 링크가 권장됩니다.하지만 링크 주위에 컨텍스트를 추가하여 동료 사용자가 그것이 무엇이며 왜 존재하는지 알 수 있도록하십시오. 대상 사이트에 연결할 수 없거나 영구적으로 오프라인 상태가되는 경우 항상 중요한 링크의 가장 중요한 부분을 인용하십시오. _ – Bugs

+0

private void signIn() { // Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent에서 사용할 때 앱이 충돌합니다. (mGoogleApiClient); // startActivityForResult (signInIntent, RC_SIGN_IN); 인 텐트 intent = 새 인 텐트 (this, Main_Tab.class); setContentView (R.layout.tab_main); startActivity (intent); } –

+0

엄마가 도와주세요. –