Main Activity를 다음과 같이 해서 성공했다.
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.widget.Toast;
import com.kakao.kakaonavi.Destination;
import com.kakao.kakaonavi.KakaoNaviParams;
import com.kakao.kakaonavi.KakaoNaviService;
import com.kakao.kakaonavi.Location;
import com.kakao.kakaonavi.NaviOptions;
import com.kakao.kakaonavi.options.CoordType;
import com.kakao.kakaonavi.options.RpOption;
import com.kakao.kakaonavi.options.VehicleType;
import java.security.MessageDigest;
import java.util.LinkedList;
import java.util.List;
import static com.kakao.kakaonavi.KakaoNaviService.*;
public class MainActivity extends AppCompatActivity {
private int position = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getAppKeyHash();
onNaviButtonClicked();
}
private void getAppKeyHash() {
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
Log.e("Hash key", something);
}
} catch (Exception e) {
// TODO Auto-generated catch block
Log.e("name not found", e.toString());
}
}
private void onNaviButtonClicked() {
position = 4;
if (position == -1) {
Toast.makeText(getApplicationContext(), "실행하고 싶은 목적지 공유 / 길 안내를 선택하세요.", Toast.LENGTH_LONG).show();
return;
}
Location kakao = Location.newBuilder("카카오 판교 오피스", 321256, 533732).build();
KakaoNaviParams params;
switch (position) {
case 1:
params = KakaoNaviParams.newBuilder(kakao).build();
KakaoNaviService.getInstance().shareDestination(this, params);
break;
case 2:
kakao = Destination.newBuilder("카카오 판교 오피스", 127.10821222694533, 37.40205604363057).build();
params = KakaoNaviParams.newBuilder(kakao).setNaviOptions(NaviOptions.newBuilder().setCoordType(CoordType.WGS84).build()).build();
KakaoNaviService.getInstance().shareDestination(this, params);
break;
case 4:
kakao = Location.newBuilder("카카오 판교 오피스", 321256, 533732).build();
params = KakaoNaviParams.newBuilder(kakao).setNaviOptions(new NaviOptions.Builder().build()).build();
KakaoNaviService.getInstance().navigate(this, params);
break;
case 5:
kakao = Destination.newBuilder("카카오 판교 오피스", 127.10821222694533, 37.40205604363057).build();
Location stop = Location.newBuilder("서서울호수공원", 126.8322289016308, 37.528495607451205).build();
List<Location> stops = new LinkedList<Location>();
stops.add(stop);
params = KakaoNaviParams.newBuilder(kakao).setNaviOptions(NaviOptions.newBuilder().setCoordType(CoordType.WGS84).build()).setViaList(stops).build();
KakaoNaviService.getInstance().navigate(this, params);
break;
case 6:
params = KakaoNaviParams.newBuilder(kakao).setNaviOptions(NaviOptions.newBuilder().setRouteInfo(true).build()).build();
KakaoNaviService.getInstance().navigate(this, params);
break;
default:
break;
}
}
}
먼저 kakao developer 사이트에 앱을 추가한다.
설정정보를 입력하는데
항목 중 "키해시"가 있다.
위 예제를 실행시키면 Log에 키해시값이 찍힌다.
그값을 입력하면 된다.
gradle.properties 는 다음과 같다. #표시된 것은 주석이므로 없어도 상관없음.
해당 값을 직접 사용되는곳에 입력해도 됨
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
KAKAO_SDK_GROUP=com.kakao.sdk
VERSION_CODE=76
KAKAO_SDK_VERSION=1.17.0
ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=27
ANDROID_BUILD_SDK_VERSION=android-27
ANDROID_BUILD_TOOL_VERSION=28.0.3
ANDROID_SUPPORT_LIB_VERSION=27.0.1
GOOGLE_PLAY_SERVICES_VERSION=12.0.1
JUNIT_VERSION=4.12
ROBOLECTRIC_VERSION=4.2
ROBOLECTRIC_SHADOW_VERSION=3.3.2
MOCKITO_VERSION=2.25.0
HAMCREST_VERSION=1.3
org.gradle.daemon=false
org.gradle.parallel=false
org.gradle.configureondemand=true
DEFAULT_PHASE=production
NEXUS_USERNAME=username
NEXUS_PASSWORD=1234
NEXUS_RELEASE_REPOSITORY_URL=url1
NEXUS_SNAPSHOT_REPOSITORY_URL=url2
-----------------------------
build.gradle(project) 은 다음과 같다.
apply plugin: 'com.android.application'
android {
compileSdkVersion ANDROID_BUILD_SDK_VERSION
defaultConfig {
applicationId "com.nobang.custom.kakaonavitest"
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation group: 'com.kakao.sdk', name: 'kakaonavi', version: project.KAKAO_SDK_VERSION
// implementation project(':libraries:kakaonavi')
implementation "com.android.support:appcompat-v7:$ANDROID_SUPPORT_LIB_VERSION"
implementation "com.android.support:design:$ANDROID_SUPPORT_LIB_VERSION"
}
-------------------
build.gradle(module) 은 다음과 같다.
apply plugin: 'com.android.application'
android {
compileSdkVersion ANDROID_BUILD_SDK_VERSION
defaultConfig {
applicationId "com.nobang.custom.kakaonavitest"
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation group: 'com.kakao.sdk', name: 'kakaonavi', version: project.KAKAO_SDK_VERSION
// implementation project(':libraries:kakaonavi')
implementation "com.android.support:appcompat-v7:$ANDROID_SUPPORT_LIB_VERSION"
implementation "com.android.support:design:$ANDROID_SUPPORT_LIB_VERSION"
}
-------------------------
설정의 세세함은 잘 모르겠으나... KAKAO Sample앱은 여러개가 한번에 있어... 잘 모르겠더군.
Navi만 사용하는 것으로 성공함.