-
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
7 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
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
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
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/notation/campusnote/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 | ||
|
||
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)}") | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/notation/campusnote/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,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) | ||
} | ||
} | ||
} |
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,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="28dp" | ||
android:height="27dp" | ||
android:viewportWidth="28" | ||
android:viewportHeight="27"> | ||
<path | ||
android:pathData="M14,0.963C6.268,0.963 0,5.75 0,11.653C0,15.324 2.424,18.56 6.116,20.485L4.563,26.093C4.425,26.588 4.999,26.983 5.439,26.696L12.248,22.255C12.822,22.31 13.406,22.342 14,22.342C21.732,22.342 28,17.556 28,11.653C28,5.75 21.732,0.963 14,0.963Z" | ||
android:fillColor="#000000" | ||
android:fillType="evenOdd"/> | ||
</vector> |
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,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".LoginActivity"> | ||
|
||
|
||
<Button | ||
android:id="@+id/kakao_login_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="카카오 로그인" | ||
android:background="@color/black" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
android:layout_marginBottom="40dp"/> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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