본문 바로가기

안드로이드

카카오톡 로그인 , 로그인 정보 가져오기

https://developers.kakao.com/docs/android 참고.. 디버그 키와 릴리즈 키를 잘 적어줘야 동작합니다.


public class KakaoLogIn extends Activity {


RbPreference pref;

private SessionCallback callback;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);


callback = new SessionCallback();

Session.getCurrentSession().addCallback(callback);

Session.getCurrentSession().checkAndImplicitOpen();


}


private class SessionCallback implements ISessionCallback {


@Override

public void onSessionOpened() {

Log.d("myLog", "onSessionOpened " + "onSessionOpened");

redirectSignupActivity();

}


@Override

public void onSessionOpenFailed(KakaoException exception) {

Log.d("myLog", "onSessionOpenFailed " + "onSessionOpenFailed");


if (exception != null) {

Logger.e(exception);

}

}

}


@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

Log.d("myLog", "onActivityResult11 " + "onActivityResult11");


if (Session.getCurrentSession().handleActivityResult(requestCode,

resultCode, data)) {

Log.d("myLog", "onActivityResult " + "onActivityResult");

return;

}


super.onActivityResult(requestCode, resultCode, data);

}


@Override

protected void onDestroy() {

super.onDestroy();

Session.getCurrentSession().removeCallback(callback);

}


protected void redirectSignupActivity() {

Log.d("myLog", "redirectSignupActivity " + "redirectSignupActivity");

requestMe();

// final Intent intent = new Intent(this, SampleSignupActivity.class);

// startActivity(intent);

// finish();

}


private void requestMe() {

UserManagement.requestMe(new MeResponseCallback() {

@Override

public void onFailure(ErrorResult errorResult) {

String message = "failed to get user info. msg=" + errorResult;


}


@Override

public void onSessionClosed(ErrorResult errorResult) {

}


@Override

public void onSuccess(UserProfile userProfile) {

Log.d("myLog", "userProfile" + userProfile.getId());

Log.d("myLog", "userProfile" + userProfile.getNickname());

Log.d("myLog",

"userProfile" + userProfile.getThumbnailImagePath());

}


@Override

public void onNotSignedUp() {

}

});

}


}

'안드로이드' 카테고리의 다른 글

T map 길찾기 구현  (0) 2016.06.20
버전별로 알람처리 방법  (0) 2016.04.12
glide PhotoViewAttacher 같이 사용시 주의점  (0) 2016.03.02
안드로이드 네이버 로그인  (0) 2015.10.14
Cannot merge new index 65608 오류  (0) 2015.09.02