개발가이드를 참고 하여 LoginButton을 LoginActivity에 올렸습니다.
그러나 클릭을 했을 때 아무런 이벤트가 일어나지 않고 있습니다.
GlobalApplication, LoginActivity 중에 잘못 된 것이 있을거 같으나 차이를 잘 찾지 못했습니다.
방법을 알려주시면 감사하겠습니다.
LoginActivity 입니다.
public class KakaoLoginActivity extends Activity{
private SessionCallback callback; //콜백 선언
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kakao_login_layout);
callback = new SessionCallback(); // 이 두개의 함수 중요함
Session.getCurrentSession().addCallback(callback);
Session.getCurrentSession().checkAndImplicitOpen();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (Session.getCurrentSession().handleActivityResult(requestCode, resultCode, data)) {
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
super.onDestroy();
Session.getCurrentSession().removeCallback(callback);
}
private class SessionCallback implements ISessionCallback {
@Override
public void onSessionOpened() {
redirectSignupActivity(); // 세션 연결성공 시 redirectSignupActivity() 호출
}
@Override
public void onSessionOpenFailed(KakaoException exception) {
if(exception != null) {
Logger.e(exception);
}
setContentView(R.layout.kakao_login_layout); // 세션 연결이 실패했을때
} // 로그인화면을 다시 불러옴
}
protected void redirectSignupActivity() { //세션 연결 성공 시 SignupActivity로 넘김
final Intent intent = new Intent(this, KakaoSignupActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
finish();
}
GlobalApplication 입니다.
public class GlobalApplication extends Application {
private Typeface notoLightFont;
private Typeface notoBoldFont;
//카카오 로그인에 필요
private static volatile GlobalApplication instance = null;
private static volatile Activity currentActivity = null;
@Override
public void onCreate() {
super.onCreate();
instance = this;
KakaoSDK.init(new KakaoSDKAdapter());
Typekit.getInstance()
//.addNormal(Typekit.createFromAsset(this, "NotoSansKR-Light-Hestia.otf"))
.addNormal(Typekit.createFromAsset(this, "NotoSansKR-Medium-Hestia.otf"))
.addBold(Typekit.createFromAsset(this, "NotoSansKR-Bold-Hestia.otf"));
/*.addItalic(Typekit.createFromAsset(this, "Double_Bubble_shadow_italic.otf"))
.addBoldItalic(Typekit.createFromAsset(this, "Double_Bubble_shadow_italic.otf"))
.addCustom1(Typekit.createFromAsset(this, "soopafre.ttf"))
.addCustom2(Typekit.createFromAsset(this, "Break It Down.ttf"));*/
notoLightFont = Typeface
.createFromAsset(this.getAssets(), "NotoSansKR-Light-Hestia.otf");
notoBoldFont = Typeface
.createFromAsset(this.getAssets(), "NotoSansKR-Bold-Hestia.otf");
}
public static GlobalApplication getGlobalApplication(Context context) {
return (GlobalApplication) context.getApplicationContext();
}
public void setNotoLightFontToView(TextView... views) {
for(TextView view : views) {
view.setTypeface(notoLightFont);
}
}
public void setNotoBoldFontToView(TextView... views) {
for(TextView view : views) {
view.setTypeface(notoBoldFont);
}
}
//카카오 SDK 부분
private static class KakaoSDKAdapter extends KakaoAdapter {
/**
* Session Config에 대해서는 default값들이 존재한다.
* 필요한 상황에서만 override해서 사용하면 됨.
* @return Session의 설정값.
*/
@Override
public ISessionConfig getSessionConfig() {
return new ISessionConfig() {
@Override
public AuthType[] getAuthTypes() {
return new AuthType[] {AuthType.KAKAO_LOGIN_ALL};
}
@Override
public boolean isUsingWebviewTimer() {
return false;
}
/* @Override
public boolean isSecureMode() {
return false;
}*/
@Override
public ApprovalType getApprovalType() {
return ApprovalType.INDIVIDUAL;
}
@Override
public boolean isSaveFormData() {
return true;
}
};
}
@Override
public IApplicationConfig getApplicationConfig() {
return new IApplicationConfig() {
@Override
public Activity getTopActivity() {
return GlobalApplication.getCurrentActivity();
}
@Override
public Context getApplicationContext() {
return GlobalApplication.getGlobalApplicationContext();
}
};
}
}
public static Activity getCurrentActivity() {
return currentActivity;
}
public static void setCurrentActivity(Activity currentActivity) {
GlobalApplication.currentActivity = currentActivity;
}
/**
* singleton 애플리케이션 객체를 얻는다.
* @return singleton 애플리케이션 객체
*/
public static GlobalApplication getGlobalApplicationContext() {
if(instance == null)
throw new IllegalStateException("this application does not inherit com.kakao.GlobalApplication");
return instance;
}
/**
* 애플리케이션 종료시 singleton 어플리케이션 객체 초기화한다.
*/
@Override
public void onTerminate() {
super.onTerminate();
instance = null;
}
//카카오 SDK 부분
}