MainActivity.kt
://kakaolink" 형식의 앱 실행 처리
package com.googsu.myapplication
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.util.Log
import android.webkit.WebChromeClient
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.FrameLayout
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.messaging.FirebaseMessaging
import kotlinx.android.synthetic.main.activity_main.*
import java.net.URISyntaxException
class MainActivity : AppCompatActivity() {
private var doubleBackToExitPressedOnce = false
private lateinit var webView: WebView
private lateinit var webViewLayout: FrameLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
webView = findViewById(R.id.webview)
webViewLayout = findViewById(R.id.webview_frame);
webView.settings.run {
javaScriptEnabled = true
domStorageEnabled = true
javaScriptCanOpenWindowsAutomatically = true
setSupportMultipleWindows(true)
}
webView.webViewClient = object: WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
Log.d("TAG url", request.url.toString())
Log.d("TAG scheme", request.url.scheme.toString())
if (request.url.scheme == "https") {
//webView.loadUrl(request.url.toString())
}
if (request.url.scheme == "intent") {
try {
Log.d("TAG scheme", intent.getPackage().toString())
val intent = Intent.parseUri(request.url.toString(), Intent.URI_INTENT_SCHEME)
// 실행 가능한 앱이 있으면 앱 실행
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
Log.d("TAG", "ACTIVITY: ${intent.`package`}")
return true
}
// Fallback URL이 있으면 현재 웹뷰에 로딩
val fallbackUrl = intent.getStringExtra("browser_fallback_url")
if (fallbackUrl != null) {
view.loadUrl(fallbackUrl)
Log.d("TAG FALLBACK", "FALLBACK: $fallbackUrl")
return true
}
Log.e("TAG", "Could not parse anythings")
} catch (e: URISyntaxException) {
Log.e("TAG", "Invalid intent request", e)
}
}
// 나머지 서비스 로직 구현
Log.d("TAG", "return false")
return false
}
}
webView.loadUrl("https://www.googsu.com/kakao_talk_message.html")
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.googsu.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_googsu"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_googsu_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- "kakao{YOUR_NATIVE_APP_KEY}://kakaolink" 형식의 앱 실행 스킴을 설정하는데 사용 -->
<data android:host="kakaolink"
android:scheme="kakaoc99999999999999a071901a19a2d86" />
</intent-filter>
</activity>
</application>
</manifest>
'카카오 REST API & SDK > 카카오톡 공유하기' 카테고리의 다른 글
카카오톡 공유하기, 메시지 커스터마이징 (0) | 2022.10.25 |
---|---|
카카오톡 미리보기 초기화 / OG(Open Graph) 캐시 삭제 (0) | 2022.08.26 |
vue.js에서 JS SDK 카카오톡 공유 사용 (0) | 2021.09.28 |
카카오 링크/메시지 androidExecutioncParams, iosExecutionParams 사용 (0) | 2021.09.27 |
카카오톡 공유하기(구. 카카오 링크) 사용중 자주 겪는 에러와 문의 (0) | 2021.04.25 |
댓글