diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f004384b..707b643b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.storage.CacheResetOnProcessCanceled.enabled - plugins { id("com.android.application") id("org.jetbrains.kotlin.android") @@ -42,6 +40,7 @@ android { } dependencies { + implementation ("com.kakao.sdk:v2-user:2.19.0") // 카카오 로그인 implementation("androidx.core:core-ktx:1.9.0") implementation("androidx.appcompat:appcompat:1.6.1") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c497668e..a46ebf1c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,10 @@ + + + + + - @@ -24,6 +28,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/notation/campusnote/GlobalApplication.kt b/app/src/main/java/com/notation/campusnote/GlobalApplication.kt new file mode 100644 index 00000000..749a4b4a --- /dev/null +++ b/app/src/main/java/com/notation/campusnote/GlobalApplication.kt @@ -0,0 +1,18 @@ +package com.notation.campusnote + +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)}") + } +} diff --git a/app/src/main/java/com/notation/campusnote/LoginActivity.kt b/app/src/main/java/com/notation/campusnote/LoginActivity.kt new file mode 100644 index 00000000..954a0404 --- /dev/null +++ b/app/src/main/java/com/notation/campusnote/LoginActivity.kt @@ -0,0 +1,49 @@ +package com.notation.campusnote + +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 + +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}") + // 성공적인 로그인 처리 추가 + } + } + } else { + UserApiClient.instance.loginWithKakaoAccount(this, callback = callback) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/icon_kakao.xml b/app/src/main/res/drawable/icon_kakao.xml new file mode 100644 index 00000000..bc828ab4 --- /dev/null +++ b/app/src/main/res/drawable/icon_kakao.xml @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 00000000..6de5c611 --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,22 @@ + + + + +