일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 안드로이드 fcm
- 66챌린지
- Android Jetpack
- Android Navigation
- Kotlin
- DataBinding
- 알고리즘 자바
- 프로그래머스 알고리즘
- android recyclerview
- WebView
- 카카오 알고리즘
- Android 12 대응
- 안드로이드 갤러리 접근
- Android Interceptor
- MVP Architecture
- 안드로이드 카카오 로그인
- 영어독립365
- Android
- 안드로이드
- Android WebView
- Kotlin FCM
- 영어공부
- 습관만들기
- Android ProgressBar
- Android DataBinding
- OkHttp Interceptor
- Android ViewPager2
- Java
- scope function
- Android 12
Archives
- Today
- Total
Developer Geek
안드로이드 카카오 SDK V2 로그인 - part2(코드) 본문
반응형
안드로이드 카카오 SDK V2 로그인 - part2(코드)
1. 카카오 로그인 API 사용을 위한 설정
[내 애플리케이션] > [제품 설정] > [카카오 로그인] 에서 카카오 로그인 을 활성화 한다.
[내 애플리케이션] > [앱 설정] > [요약 정보] 에서 네이트브 앱 키를 복사해서 아래와 같이 작성한다.
코드 작성
- GlobalApplication.kt (Application을 상속받는 클래스) 생성한다.
아래와 같이 onCreate함수 내에 KakaoSdk.init()을 실행한다. class GlobalApplication: Application() { override fun onCreate() { super.onCreate() KakaoSdk.init(this, getString(R.string.kakao_app_key)) } }
- AndroidManifest.xml 파일에서 application 태그 속성 값으로
android:name=".GlobalApplication"
을 추가한다.
- 아래와 같이 AndroidManifest.xml 파일에서 application 태그 안에 코드를 추가하여 Redirect URI 설정한다.
(예를 들어 네이티브 앱 키가 '123456789'라면 'kakao123456789'를 입력한다.)
<activity android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Redirect URI: "kakao{NATIVE_APP_KEY}://oauth" -->
<data android:host="oauth"
android:scheme="kakaoadf1f3ccd6e66fea62118ef585896c09" />
</intent-filter>
</activity>
- 화면에 버튼을 만든다.
[activity_main.xml]<?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=".MainActivity"> <androidx.constraintlayout.utils.widget.ImageFilterButton android:id="@+id/btn_kakao_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/kakao_login_large_narrow" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias=".7" /> </androidx.constraintlayout.widget.ConstraintLayout>
- 로그인 로직을 구현한다.
[MainActivity.kt]
<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=".MainActivity">
<androidx.constraintlayout.utils.widget.ImageFilterButton
android:id="@+id/btn_kakao_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/kakao_login_large_narrow"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias=".7" />
</androidx.constraintlayout.widget.ConstraintLayout>
반응형
'안드로이드' 카테고리의 다른 글
Android 키보드 생성 시, Bottom Navigation Hide (0) | 2021.10.28 |
---|---|
안드로이드 style.xml 사용 예제 (0) | 2021.10.19 |
안드로이드 문자열 리소스(strings.xml) 사용 예제 (0) | 2021.10.19 |
안드로이드 카카오 SDK V2 로그인 - part1(프로젝트 셋업) (0) | 2021.09.27 |
Android(Kotlin) RecyclerView Example (0) | 2021.09.08 |
Comments