- 아래와 같이 코딩 했는데, 카톡 공유하면 여전히 intent:kakaolink: 이렇게 에러가 납니다ㅠ 도와주세요 형님덜~ ㅠㅠ
웹뷰 구현 중인데, 카카오링크 공유하기가 계속 에러가 나고 안되네요;;
- gradle (Project)
allprojects {
repositories {
google()
jcenter()
// 카카오 SDK 레포지토리 설정
maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/' }
}
}
2. gradle (Module)
//자바 버전 설정
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
생략
// 카카오 SDK 모듈 설정
implementation "com.kakao.sdk:v2-user:2.4.2" // 카카오 로그인
implementation "com.kakao.sdk:v2-talk:2.4.2" // 친구, 메시지(카카오톡)
implementation "com.kakao.sdk:v2-story:2.4.2" // 카카오스토리
implementation "com.kakao.sdk:v2-link:2.4.2" // 메시지(카카오링크)
implementation "com.kakao.sdk:v2-navi:2.4.2" // 카카오내비
}
3. Manifest
<!-- "kakao{YOUR_NATIVE_APP_KEY}://kakaolink" 형식의 앱 실행 스킴을 설정하는데 사용 -->
<data android:host="kakaolink"
android:scheme="kakao{29947cfd9a52f18de668f1b2a3bf0867}" />
</application>
- MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Kakao SDK 초기화
KakaoSdk.init(this, "{29947cfd9a52f18de668f1b2a3bf0867}");
private class myWebViewClient extends WebViewClient {
public static final String INTENT_PROTOCOL_START = “intent:”;
public static final String INTENT_PROTOCOL_INTENT = “#Intent;”;
public static final String INTENT_PROTOCOL_END = “;end;”;
public static final String GOOGLE_PLAY_STORE_PREFIX = “market://details?id=”;
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith(INTENT_PROTOCOL_START)) {
final int customUrlStartIndex = INTENT_PROTOCOL_START.length();
final int customUrlEndIndex = url.indexOf(INTENT_PROTOCOL_INTENT);
if (customUrlEndIndex < 0) {
return false;
} else {
final String customUrl = url.substring(customUrlStartIndex, customUrlEndIndex);
try {
getBaseContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(customUrl)));
} catch (ActivityNotFoundException e) {
final int packageStartIndex = customUrlEndIndex + INTENT_PROTOCOL_INTENT.length();
final int packageEndIndex = url.indexOf(INTENT_PROTOCOL_END);
final String packageName = url.substring(packageStartIndex, packageEndIndex < 0 ? url.length() : packageEndIndex);
getBaseContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(GOOGLE_PLAY_STORE_PREFIX + packageName)));
}
return true;
}
} else {
return false;
}
}
}