-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/notation/campusnote/login/GlobalApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.notation.campusnote.login | ||
|
||
import android.app.Application | ||
import android.util.Log | ||
import com.kakao.sdk.common.KakaoSdk | ||
import com.kakao.sdk.common.util.Utility | ||
|
||
|
||
class GlobalApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
//Kakao SDK 초기화 | ||
KakaoSdk.init(this, "3fb9a572bb1f2e3cd66d370d2f7888dd") | ||
|
||
Log.d("hash", "keyhash : ${Utility.getKeyHash(this)}") | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/notation/campusnote/login/LoginActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.notation.campusnote.login | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.notation.campusnote.databinding.ActivityLoginBinding | ||
import com.kakao.sdk.auth.model.OAuthToken | ||
import com.kakao.sdk.user.UserApiClient | ||
import com.notation.campusnote.signUp.SignUpActivity | ||
|
||
class LoginActivity :AppCompatActivity(){ | ||
private val TAG = "KakaoLoginExample" | ||
private lateinit var binding: ActivityLoginBinding | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityLoginBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
binding.kakaoLoginButton.setOnClickListener { | ||
login() | ||
} | ||
} | ||
|
||
private fun login() { | ||
// 카카오계정으로 로그인 공통 콜백 설정 | ||
val callback: (OAuthToken?, Throwable?) -> Unit = { token, error -> | ||
if (error != null) { | ||
Log.e(TAG, "카카오계정으로 로그인 실패", error) | ||
} else if (token != null) { | ||
Log.i(TAG, "카카오계정으로 로그인 성공 ${token.accessToken}") | ||
} | ||
} | ||
|
||
// 카카오톡이 설치되어 있으면 카카오톡으로 로그인, 아니면 카카오계정으로 로그인 | ||
if (UserApiClient.instance.isKakaoTalkLoginAvailable(this)) { | ||
UserApiClient.instance.loginWithKakaoTalk(this) { token, error -> | ||
if (error != null) { | ||
Log.e(TAG, "카카오톡으로 로그인 실패", error) | ||
|
||
// 특정 상황(취소 등)에 대한 처리 추가 | ||
} else if (token != null) { | ||
Log.i(TAG, "카카오톡으로 로그인 성공 ${token.accessToken}") | ||
// 성공적인 로그인 처리 추가 | ||
val intent = Intent(this, SignUpActivity::class.java) | ||
startActivity(intent) | ||
} | ||
} | ||
} else { | ||
UserApiClient.instance.loginWithKakaoAccount(this, callback = callback) | ||
} | ||
} | ||
|
||
private fun updateKakaoLoginUi() { | ||
UserApiClient.instance.me { user, error -> | ||
if (error != null) { | ||
Log.e(TAG, "사용자 정보 요청 실패", error) | ||
} | ||
else if (user != null) { | ||
Log.i(TAG, "사용자 정보 요청 성공" + | ||
"\n회원번호: ${user.id}" + | ||
"\n프로필사진: ${user.kakaoAccount?.profile?.thumbnailImageUrl}") | ||
} | ||
} | ||
} | ||
} |