public class MainActivity extends AppCompatActivity {
private static String TAG = "[Sosim]";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
redirectLoginActivity();
System.out.println("your hash: " + getKeyHash(this));
}
private void onClickLogout() {
UserManagement.getInstance().requestLogout(new LogoutResponseCallback() {
@Override
public void onCompleteLogout() {
redirectLoginActivity();
}
});
}
public void redirectLoginActivity() {
Toast.makeText(getApplicationContext(), "redirect login0", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
}
public static String getKeyHash(Context context) {
PackageInfo packageInfo = null;
try {
packageInfo = context.getApplicationContext().getPackageManager().getPackageInfo("com.goldenmine.sosim2", PackageManager.GET_SIGNATURES);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null)
return null;
for (Signature signature : packageInfo.signatures) {
try {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
return Base64.encodeToString(md.digest(), Base64.NO_WRAP);
} catch (NoSuchAlgorithmException e) {
Log.w(TAG, "Unable to get MessageDigest. signature=" + signature, e);
}
}
return null;
}
}
public class LoginActivity extends AppCompatActivity {
private SessionCallback callback;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
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();
}
@Override
public void onSessionOpenFailed(KakaoException exception) {
System.out.println("errtype: " + exception.getErrorType());
if (exception != null) {
//Logger.e(exception);
exception.printStackTrace();
}
Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show();
}
}
protected void redirectSignupActivity() {
Toast.makeText(getApplicationContext(), "redirect signup1", Toast.LENGTH_SHORT).show();
final Intent intent = new Intent(this, SignupActivity.class);
startActivity(intent);
finish();
}
}
public class SignupActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
requestMe();
}
private void requestMe() {
List<String> keys = new ArrayList<>();
keys.add("properties.nickname");
keys.add("properties.profile_image");
keys.add("kakao_account.email");
UserManagement.getInstance().me(keys, new MeV2ResponseCallback() {
@Override
public void onFailure(ErrorResult errorResult) {
String message = "failed to get user info. msg=" + errorResult;
//Logger.d(message);
System.out.println(message);
}
@Override
public void onSessionClosed(ErrorResult errorResult) {
redirectLoginActivity();
}
@Override
public void onSuccess(MeV2Response response) {
//Logger.d("user id : " + response.getId());
//Logger.d("email: " + response.getKakaoAccount().getEmail());
//Logger.d("profile image: " + response.getKakaoAccount()
// .getProfileImagePath());
Toast.makeText(getApplicationContext(), "id: " + response.getId() + ", email:" + response.getKakaoAccount().getEmail(), Toast.LENGTH_SHORT).show();
redirectMainActivity();
}
});
}
public void redirectMainActivity() {
Toast.makeText(getApplicationContext(), "redirect main2", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
public void redirectLoginActivity() {
Toast.makeText(getApplicationContext(), "redirect login2", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
}
}
카카오 연동 처음해보는 초보입니다
위와 같이 코드를 짰는데 카카오톡 로그인을 하려고 하면 onSessionOpenFailed가 됩니다
1주일째 보고있는데 문제를 도통 모르겠네요 살려주세요 ㅠ