developers.kakao.com/docs/latest/ko/getting-started/sdk-android-v1
buld.gradle(Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven{
url "https://maven.google.com"
}
/*카카오*/
maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module)
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// 카카오 로그인
implementation group: 'com.kakao.sdk', name: 'usermgmt', version: '1.30.6'
// 카카오톡
implementation group: 'com.kakao.sdk', name: 'kakaotalk', version: '1.30.6'
// 카카오스토리
implementation group: 'com.kakao.sdk', name: 'kakaostory', version: '1.30.6'
// 카카오링크
implementation group: 'com.kakao.sdk', name: 'kakaolink', version: '1.30.6'
// 카카오내비
implementation group: 'com.kakao.sdk', name: 'kakaonavi', version: '1.30.6'
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<com.kakao.usermgmt.LoginButton
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="30dp" />
</LinearLayout>
MainActivity.java
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.kakao.auth.ISessionCallback;
import com.kakao.auth.Session;
import com.kakao.util.exception.KakaoException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 세션 콜백 등록
Session.getCurrentSession().addCallback(sessionCallback);
}
// 세션 콜백 구현
private ISessionCallback sessionCallback = new ISessionCallback() {
@Override
public void onSessionOpened() {
Log.i("KAKAO_SESSION", "로그인 성공");
}
@Override
public void onSessionOpenFailed(KakaoException exception) {
Log.e("KAKAO_SESSION", "로그인 실패", exception);
}
};
@Override
protected void onDestroy() {
super.onDestroy();
// 세션 콜백 삭제
Session.getCurrentSession().removeCallback(sessionCallback);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
// 카카오톡|스토리 간편로그인 실행 결과를 받아서 SDK로 전달
if (Session.getCurrentSession().handleActivityResult(requestCode, resultCode, data)) {
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".GlobalApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<meta-data
android:name="com.kakao.sdk.AppKey"
android:value="@string/kakao_app_key" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
'카카오 REST API & SDK > 카카오 로그인' 카테고리의 다른 글
모바일웹에서 "카카오톡으로 로그인" 버튼은 언제 표시될까? (0) | 2021.05.03 |
---|---|
카카오톡 인앱브라우저에서 자동로그인 (0) | 2021.04.18 |
android + (kakao Javascript SDK)하이브리드앱 예제 - 카카오 로그인 (0) | 2021.03.21 |
react + react-kakao-login 예제 - 카카오 로그인 (0) | 2021.03.21 |
node.js + axios 예제 - Unlink (0) | 2021.03.14 |
댓글