This document describes how to integrate Kakao Link APIs into your service with the Kakao SDK for Android (hereinafter referred to as 'Android SDK').
To use the Android SDK, you must register the Android platform in advance. Go to [My Application] > [Platform] and register the Android platform by specifying its package name and key hashes. If not, an error may occur.
To use the Kakao Link, you need to add v2-link
(Kakao Link module) that provides LinkClient
in the module-level build.gradle file by referring to Add modules.
If you use the Android SDK 2.4.0 or higher, this setting is not required.
In Android 11, you must define how your app queries and interacts with the Kakao Talk app to send a message through Kakao Talk. If your app targets Android 11 or higher, add the queries
element to AndroidManifest.xml, and set the package name to com.kakao.talk
inside the queries
element.
<manifest package="com.example.sample">
<!--Add Kakao Talk package inside the `queries` element.-->
<queries>
<package android:name="com.kakao.talk" />
</queries>
...
</manifest>
Refer to Package visibility in Android 11 for more details.
According to your service's purpose and requirements, you need to decide which API to use first by considering their characteristics and difference.
Step 1. Select a type of Messaging APIThere are two types of messaging APIs: Kakao Link and Kakao Talk messaging API. You need to understand the differences between the two messaging APIs completely by referring to Understand concepts, and decide which API to use to implement the function to send a message.
Decide which message template to use by referring to Message template > Types.
You can configure a message according to the default template in JSON format or create a custom template in person for your service. Refer to Message configuration method for more details.
After configuring a message, you must call the corresponding API according to the desired message template type. If the request is successful, the Android SDK launches Kakao Talk or lets a user log in with Kakao Account on a web page, and then shows a list of friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
To make your app launch when a user clicks on a clickable component on the Kakao Talk message, you must set a Custom URL Scheme to launch an app in AndroidManifest.xml.
<activity
android:name=".${YOUR_ACTIVITY_NAME}"
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" />
<!-- Set a scheme to launch an app in "kakao${YOUR_NATIVE_APP_KEY}://kakaolink" format. -->
<data android:host="kakaolink"
android:scheme="kakao${YOUR_NATIVE_APP_KEY}" />
</intent-filter>
</activity>
You can set additional parameters when running the app as needed by using androidExecutionParams
for Android SDK or iosExecutionParams
for iOS SDK. If you have defined the parameters, they are added to the Custom URL Schemes as follows.
kakao${YOUR_NATIVE_APP_KEY}://kakaolink${androidExecutionParams}
kakao${YOUR_NATIVE_APP_KEY}://kakaolink${iosExecutionParams}
When you configure a Kakao Talk message through the Kakao Link or Kakao Talk messaging APIs, use one of the classes defined in com.kakao.sdk.template
according to a message type by referring to Message template components. Then, create an object for the desired message type among five types, and define the message content for the template object.
Here are the code snippets showing how to configure a message for each message type.
val defaultFeed = FeedTemplate(
content = Content(
title = "Strawberry Cheese Cake",
description = "#Cake #Strawberry #Sampyeong-dong #Cafe #Vibe #BlindDate",
imageUrl = "https://mud-kage.kakao.com/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png",
link = Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
),
itemContent = ItemContent(
profileText = "Kakao",
profileImageUrl = "https://mud-kage.kakao.com/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png",
titleImageUrl = "https://mud-kage.kakao.com/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png",
titleImageText = "Cheese cake",
titleImageCategory = "cake",
items = listOf(
ItemInfo(item = "cake1", itemOp = "1000 won"),
ItemInfo(item = "cake2", itemOp = "2000 won"),
ItemInfo(item = "cake3", itemOp = "3000 won"),
ItemInfo(item = "cake4", itemOp = "4000 won"),
ItemInfo(item = "cake5", itemOp = "5000 won")
),
sum = "Total",
sumOp = "15000 won"
),
social = Social(
likeCount = 286,
commentCount = 45,
sharedCount = 845
),
buttons = listOf(
Button(
"View on Web",
Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
),
Button(
"View on App",
Link(
androidExecutionParams = mapOf("key1" to "value1", "key2" to "value2"),
iosExecutionParams = mapOf("key1" to "value1", "key2" to "value2")
)
)
)
)
val defaultList = ListTemplate(
headerTitle = "WEEKLY MAGAZINE",
headerLink = Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
),
contents = listOf(
Content(
title = "My hobby, Table tennis",
description = "Sports",
imageUrl = "https://mud-kage.kakao.com/dn/bDPMIb/btqgeoTRQvd/49BuF1gNo6UXkdbKecx600/kakaolink40_original.png",
link = Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
),
Content(
title = "Understanding coffee with cream",
description = "Food",
imageUrl = "https://mud-kage.kakao.com/dn/QPeNt/btqgeSfSsCR/0QJIRuWTtkg4cYc57n8H80/kakaolink40_original.png",
link = Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
),
Content(
title = "Emotional atmosphere",
description = "Photo",
imageUrl = "https://mud-kage.kakao.com/dn/c7MBX4/btqgeRgWhBy/ZMLnndJFAqyUAnqu4sQHS0/kakaolink40_original.png",
link = Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
)
),
buttons = listOf(
Button(
"View on Web",
Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
),
Button(
"View on App",
Link(
androidExecutionParams = mapOf("key1" to "value1", "key2" to "value2"),
iosExecutionParams = mapOf("key1" to "value1", "key2" to "value2")
)
)
)
)
val defaultLocation = LocationTemplate(
address = "235, Pangyoyeok-ro, Bundang-gu, Seongnam-si, Gyeonggi-do",
addressTitle = "Kakao Pangyo Office Cafe Talk",
content = Content(
title = "New menu release❤️ Cherry Blossom Latte",
description = "Cherry blossom latte 1+1 for this week",
imageUrl = "https://mud-kage.kakao.com/dn/bSbH9w/btqgegaEDfW/vD9KKV0hEintg6bZT4v4WK/kakaolink40_original.png",
link = Link(
webUrl = "https://developers.com",
mobileWebUrl = "https://developers.kakao.com"
)
),
social = Social(
likeCount = 286,
commentCount = 45,
sharedCount = 845
)
)
val defaultCommerce = CommerceTemplate(
content = Content(
title = "Ivory long dress (4 Color)",
imageUrl = "https://mud-kage.kakao.com/dn/RY8ZN/btqgOGzITp3/uCM1x2xu7GNfr7NS9QvEs0/kakaolink40_original.png",
link = Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
),
commerce = Commerce(
regularPrice = 208800,
discountPrice = 146160,
discountRate = 30,
productName = "Ivory long dress"
),
buttons = listOf(
Button(
"Purchase",
Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
),
Button(
"Share",
Link(
androidExecutionParams = mapOf("key1" to "value1", "key2" to "value2"),
iosExecutionParams = mapOf("key1" to "value1", "key2" to "value2")
)
)
)
)
val defaultText = TextTemplate(
text = """
The Text template provided as a default template can contain text up to 200 characters. The Text template has a text area and a default button. You can also add an additional button. If you use Kakao Link, you can send a message with a more extended form of templates, such as sending multiple images and profile information.
""".trimIndent(),
link = Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
)
As an example, here are the steps to configure and send a Feed message.
Step 1. Figure out template componentsCheck which object you should create for a Feed message by referring to Message template > Feed message. Feed message is defined as the FeedTemplate class.
Create the FeedTemplate
object by referring to the guide and reference. As you check in Step 1, the Feed message contains content
, social
, buttonTitle
, buttons
, and itemContent
components. You must declare the required component, content
for Feed message, in the object.
Pass the FeedTemplate
object created in Step 2 when calling Kakao Link or Kakao Talk messaging API.
This API enables you to configure a message in JSON format according to the default template type to use and share it through Kakao Talk.
To figure out if it is possible to share a message through Kakao Talk, call the isKakaoLinkAvailable
method that checks if Kakao Talk has been installed. If Kakao Talk is installed, call defaultTemplate
that shares a message through Kakao Talk. If not installed, call defaultTemplateUri
in the WebSharerClient
class to declare a URL for sharing and open the URL WebView or a default browser.
Name | Type | Description | Required |
---|---|---|---|
context | Context |
Refer to Context. | O |
defaultTemplate | DefaultTemplate |
Object of the message template to be sent. You must create an object of the class for the desired template. Refer to Configure a message. |
O |
serverCallbackArgs | Map<String, String> |
Used when you want to get a callback from Kakao to your service server when a message is successfully sent. Refer to Set Kakao Link success callback. |
X |
// Send a Feed message.
// Check if Kakao Talk has been installed.
if (LinkClient.instance.isKakaoLinkAvailable(context)) {
// Possible to share Kakao Link message through Kakao Talk.
LinkClient.instance.defaultTemplate(context, defaultFeed) { linkResult, error ->
if (error != null) {
Log.e(TAG, "Failed to send Kakao Link.", error)
}
else if (linkResult != null) {
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}
}
} else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// Example of sharing URI via web
val sharerUrl = WebSharerClient.instance.defaultTemplateUri(defaultFeed)
// Open URI through CustomTabs.
// 1. Open URI on Chrome browser through CustomTabs.
try {
KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
} catch(e: UnsupportedOperationException) {
// Exception handling if Chrome browser is not used.
}
// 2. Open URI on device's default browser through CustomTabs.
try {
KakaoCustomTabsClient.open(context, sharerUrl)
} catch (e: ActivityNotFoundException) {
// Exception handling if Internet browser is not used.
}
}
var disposables = CompositeDisposable()
// Send a Feed message.
LinkClient.rx.defaultTemplate(context, defaultFeed)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ linkResult ->
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}, { error ->
Log.e(TAG, "Failed to send Kakao Link.", error)
})
.addTo(disposables)
Calling defaultTemplate()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
defaultTemplate()
returns LinkResult. Since the Kakao Link API does not inform the result of message delivery, implement Kakao Link success callback.
Name | Type | Description | Required |
---|---|---|---|
intent | Intent |
Intent to invoke Kakao link with the requested template. | O |
argumentMsg | Map<String, String> |
Result of templateArgs validation. | O |
warningMsg | Map<String, String> |
Result of template validation. | O |
This API enables you to customize a template in [Tools] > [Message Template Builder] and send a message through Kakao Talk.
To figure out if it is possible to share a message through Kakao Talk, call the isKakaoLinkAvailable
method that checks if Kakao Talk has been installed. If Kakao Talk is installed, call customTemplate
that shares a message through Kakao Talk. If not installed, call customTemplateUri
in the WebSharerClient
class to declare a URL for sharing and open the URL WebView or a default browser.
Name | Type | Description | Required |
---|---|---|---|
context | Context |
Refer to Context. | O |
templateId | Long |
Template ID of the custom template registered in [Tools] > [Message Template Builder]. Refer to Message template builder. |
O |
templateArgs | Map<String, String> |
If the specified template contains a user argument, use this parameter to pass key-value pairs. You cannot overwrite the scrap result. |
X |
serverCallbackArgs | Map<String, String> |
Used when you want to get a callback from Kakao to your service server when a message is successfully sent. Refer to Set Kakao Link success callback. |
X |
// Template ID of the custom template.
// * Refer to the guide: https://developers.kakao.com/docs/latest/en/message/message-template
val templateId = templateIds["customMemo"] as Long
// Check if Kakao Talk has been installed.
if (LinkClient.instance.isKakaoLinkAvailable(context)) {
// Possible to share Kakao Link message through Kakao Talk.
LinkClient.instance.customTemplate(context, templateId) { linkResult, error ->
if (error != null) {
Log.e(TAG, "Failed to send Kakao Link.", error)
}
else if (linkResult != null) {
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}
}
} else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// Example of sharing URI via web
val sharerUrl = WebSharerClient.instance.customTemplateUri(templateId)
// Open URI through CustomTabs.
// 1. Open URI on Chrome browser through CustomTabs.
try {
KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
} catch(e: UnsupportedOperationException) {
// Exception handling if Chrome browser is not used.
}
// 2. Open URI on device's default browser through CustomTabs.
try {
KakaoCustomTabsClient.open(context, sharerUrl)
} catch (e: ActivityNotFoundException) {
// Exception handling if Internet browser is not used.
}
}
var disposables = CompositeDisposable()
// Template ID of the custom template.
// * Refer to the guide: https://developers.kakao.com/docs/latest/en/message/message-template
val templateId = templateIds["customMemo"] as Long
LinkClient.rx.customTemplate(context, templateId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ linkResult ->
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}, { error ->
Log.e(TAG, "Failed to send Kakao Link.", error)
})
.addTo(disposables)
Calling customTemplate()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
customTemplate()
returns LinkResult. Since the Kakao Link API does not inform the result of message delivery, implement Kakao Link success callback.
This API scraps a web page, configures a message based on the scraped web page information, and then sends it through Kakao Talk.
To figure out if it is possible to share a message through Kakao Talk, call the isKakaoLinkAvailable
method that checks if Kakao Talk has been installed. If Kakao Talk is installed, call scrapTemplate
that shares a message through Kakao Talk. If not installed, call scrapTemplateUri
in the WebSharerClient
class to declare a URL for sharing and open the URL WebView or a default browser.
Name | Type | Description | Required |
---|---|---|---|
context | Context |
Refer to Context. | O |
url | String |
Web page URL to be scraped. | O |
serverCallbackArgs | Map<String, String> |
Used when you want to get a callback from Kakao to your service server when a message is successfully sent. Refer to Set Kakao Link success callback. |
X |
// Web page URL to be shared.
// * CAUTION: The domain of the URL to be shared must be registered in [My Appliction] > [Platform] > [Web] in Kakao Developers.
val url = "https://developers.kakao.com"
// Check if Kakao Talk has been installed.
if (LinkClient.instance.isKakaoLinkAvailable(context)) {
// Possible to share Kakao Link message through Kakao Talk.
LinkClient.instance.scrapTemplate(context, url) { linkResult, error ->
if (error != null) {
Log.e(TAG, "Failed to send Kakao Link.", error)
}
else if (linkResult != null) {
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}
}
} else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// Example of sharing URI via web
val sharerUrl = WebSharerClient.instance.scrapTemplateUri(url)
// Open URI through CustomTabs.
// 1. Open URI on Chrome browser through CustomTabs.
try {
KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
} catch(e: UnsupportedOperationException) {
// Exception handling if Chrome browser is not used.
}
// 2. Open URI on device's default browser through CustomTabs.
try {
KakaoCustomTabsClient.open(context, sharerUrl)
} catch (e: ActivityNotFoundException) {
// Exception handling if Internet browser is not used.
}
}
var disposables = CompositeDisposable()
// Web page URL to be shared.
// * CAUTION: The domain of the URL to be shared must be registered in [My Appliction] > [Platform] > [Web] in Kakao Developers.
val url = "https://developers.kakao.com"
LinkClient.rx.scrapTemplate(context, url)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ linkResult ->
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}, { error ->
Log.e(TAG, "Failed to send Kakao Link.", error)
})
.addTo(disposables)
Calling scrapTemplate()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
scrapTemplate()
returns LinkResult. Since the Kakao Link API does not inform the result of message delivery, implement Kakao Link success callback.
This API scraps a web page, configures a message based on the scraped web page information, and then sends it through Kakao Talk. You can use a custom template registered in [Tools] > [Message Template Builder] when requesting to send a scrap message.
To figure out if it is possible to share a message through Kakao Talk, call the isKakaoLinkAvailable
method that checks if Kakao Talk has been installed. If Kakao Talk is installed, call scrapTemplate
that shares a message through Kakao Talk. If not installed, call scrapTemplateUri
in the WebSharerClient
class to declare a URL for sharing and open the URL WebView or a default browser.
Name | Type | Description | Required |
---|---|---|---|
context | Context |
Refer to Context. | O |
url | String |
Web page URL to be scraped. | O |
templateId | Long |
Used when you want to send a scrap message with the template registered in [Tools] > [Message Template Builder]. Specify the ID of the template to apply. When you use this parameter, the scraped content is applied in the template with the specified templateId . |
O |
templateArgs | Map<String, String> |
If you specify templateId and the specifed template contains other user arguments besides the default argument keys, pass the user arguments using this parameter in key:value format.You cannot overwrite the scrap result. |
X |
serverCallbackArgs | Map<String, String> |
Used when you want to get a callback from Kakao to your service server when a message is successfully sent. Refer to Set Kakao Link success callback. |
X |
// Web page URL to be shared.
// * CAUTION: The domain of the URL to be shared must be registered in [My Appliction] > [Platform] > [Web] in Kakao Developers.
val url = "https://developers.kakao.com"
val templateId = templateIds["customMemo"] as Long
// Check if Kakao Talk has been installed.
if (LinkClient.instance.isKakaoLinkAvailable(context)) {
// Possible to share Kakao Link message through Kakao Talk.
LinkClient.instance.scrapTemplate(context, url, templateId) { linkResult, error ->
if (error != null) {
Log.e(TAG, "Failed to send Kakao Link.", error)
}
else if (linkResult != null) {
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}
}
} else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// Example of sharing URI via web
val sharerUrl = WebSharerClient.instance.scrapTemplateUri(url, templateId)
// Open URI through CustomTabs.
// 1. Open URI on Chrome browser through CustomTabs.
try {
KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
} catch(e: UnsupportedOperationException) {
// Exception handling if Chrome browser is not used.
}
// 2. Open URI on device's default browser through CustomTabs.
try {
KakaoCustomTabsClient.open(context, sharerUrl)
} catch (e: ActivityNotFoundException) {
// Exception handling if Internet browser is not used.
}
}
var disposables = CompositeDisposable()
val templateId = templateIds["customMemo"] as Long
// Web page URL to be shared.
// * CAUTION: The domain of the URL to be shared must be registered in [My Appliction] > [Platform] > [Web] in Kakao Developers.
val url = "https://developers.kakao.com"
LinkClient.rx.scrapTemplate(context, url, templateId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ linkResult ->
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}, { error ->
Log.e(TAG, "Failed to send Kakao Link.", error)
})
.addTo(disposables)
Calling scrapTemplate()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
scrapTemplate()
returns LinkResult. Since the Kakao Link API does not inform the result of message delivery, implement Kakao Link success callback.
The Kakao Link success callback is a function to send a callback request to the URL specified on Kakao Developers when a Kakao Link message is successfully sent to friends or a chatroom selected by a user. This function is only available for Kakao Link API, not for Kakao Talk messaging API.
To use this feature, you need to:
To use the Kakao Link callback function, you must specify a custom parameter through serverCallbackArgs
. Otherwise, Kakao Link success callback is not delivered even though you registered Kakao Link callback URL in [My Application]. When your service server receives a Kakao Link success callback, you can figure out additional information through the predefined custom parameters, such as what content the user has shared.
To pass additional information when requesting the Kakao Link API, declare serverCallbackArgs
, and pass keys and values as a Map. Here is a code snippet showing how to set parameters for Kakao Link success callback.
// Template ID of the custom template.
// * Refer to the guide: https://developers.kakao.com/docs/latest/en/message/message-template
val templateId = templateIds["customMemo"] as Long
// Set callback parameter.
val serverCallbackArgs = mapOf(templateId to "templateId")
// Check if Kakao Talk has been installed.
if (LinkClient.instance.isKakaoLinkAvailable(context)) {
// Possible to share Kakao Link message through Kakao Talk.
LinkClient.instance.customTemplate(context, templateId, serverCallbackArgs) { linkResult, error ->
if (error != null) {
Log.e(TAG, "Failed to send Kakao Link.", error)
}
else if (linkResult != null) {
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}
}
} else {
// If Kakao Talk is not installed, it is recommended to share URI via web.
// Example of sharing URI via web
val sharerUrl = WebSharerClient.instance.customTemplateUri(templateId, serverCallbackArgs)
// Open URI through CustomTabs.
// 1. Open URI on Chrome browser through CustomTabs.
try {
KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
} catch(e: UnsupportedOperationException) {
// Exception handling if Chrome browser is not used.
}
// 2. Open URI on device's default browser through CustomTabs.
try {
KakaoCustomTabsClient.open(context, sharerUrl)
} catch (e: ActivityNotFoundException) {
// Exception handling if Internet browser is not used.
}
}
var disposables = CompositeDisposable()
// Template ID of the custom template.
// * Refer to the guide: https://developers.kakao.com/docs/latest/en/message/message-template
val templateId = templateIds["customMemo"] as Long
// Set callback parameter.
val serverCallbackArgs = mapOf(templateId to "templateId")
LinkClient.rx.customTemplate(context, templateId, serverCallbackArgs)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ linkResult ->
Log.d(TAG, "Succeeded in sending Kakao Link. ${linkResult.intent}")
startActivity(linkResult.intent)
// If you get this message even though Kakao Link is successfully sent, some contents may not be displayed normally.
Log.w(TAG, "Warning Msg: ${linkResult.warningMsg}")
Log.w(TAG, "Argument Msg: ${linkResult.argumentMsg}")
}, { error ->
Log.e(TAG, "Failed to send Kakao Link.", error)
})
.addTo(disposables)
If the Kakao Link message has successfully been delivered, Kakao sends a success callback including the specified parameters to the Kakao Link callback URL of your service server. For more information on the callback request, refer to Reference Information > Kakao Link success callback.
You can attach images to a Kakao Talk message by passing an image URL when configuring a message template or uploading images in the Message template builder in advance. To use the image file stored on your device for a message, you must upload the image file to the server first to obtain its URL value.
If it is difficult to obtain the image file URL, you can either upload an image file to the Kakao Link server or scrap it. The images uploaded to the Kakao Link server are stored for up to 20 days and automatically deleted after the period.
To upload an image, call the imageUpload()
method defined in LinkClient
. You can only upload an image with a file size of 2 MB or less.
Name | Type | Description | Required |
---|---|---|---|
image | File |
Image file to be uploaded. | O |
secureResource | Boolean |
Whether to use HTTPS for the image URL scheme. - true : HTTPS is used. - false : HTTP is used.(Default: true ) |
X |
callback | ( ImageUploadResult ?, Throwable?) -> Unit |
Callback function that gets invoked when the operation is completed. | X |
// Upload an image.
// Local image file.
// This sample uses an image file added as a project resource. Use an image file needed for your service in real.
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.sample1)
val file = File(context.cacheDir, "sample1.png")
val stream = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
stream.close()
// Upload an image to the Kakao image server.
LinkClient.instance.uploadImage(file) { imageUploadResult, error ->
if (error != null) {
Log.e(TAG, "Failed to upload an image.", error)
}
else if (imageUploadResult != null) {
Log.i(TAG, "Succeeded in upload an image. \n${imageUploadResult.infos.original}")
}
}
var disposables = CompositeDisposable()
// Upload an image.
// Local image file.
// This sample uses an image file added as a project resource. Use an image file needed for your service in real.
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.sample1)
val file = File(context.cacheDir, "sample1.png")
val stream = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
stream.close()
// Upload an image to the Kakao image server.
LinkClient.rx.uploadImage(file)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ imageUploadResult ->
Log.i(TAG, "Succeeded in upload an image. \n${imageUploadResult.infos.original}")
}, { error ->
Log.e(TAG, "Failed to upload an image.", error)
}).addTo(disposables)
To use an image by scraping an image uploaded on the web page, call the scrapImage()
method defined in LinkClient
.
Name | Type | Description | Required |
---|---|---|---|
imageUrl | String |
URL of the image to be scrapped. | O |
secureResource | Boolean |
Whether to use HTTPS for the image URL scheme. If true , HTTPS is used. (Default: true ) |
X |
callback | ( ImageUploadResult ?, Throwable?) -> Unit |
Callback function that gets invoked when the operation is completed. | X |
// Scrape an image.
// URL of the original image.
val url = "https://t1.kakaocdn.net/kakaocorp/Service/KakaoTalk/pc/slide/talkpc_theme_01.jpg"
// Upload an image to the Kakao image server.
LinkClient.instance.scrapImage(url) { imageUploadResult, error ->
if (error != null) {
Log.e(TAG, "Failed to scrape an image.", error)
}
else if (imageUploadResult != null) {
Log.i(TAG, "Succeeded in scraping an image. \n${imageUploadResult.infos.original}")
}
}
var disposables = CompositeDisposable()
// Scrape an image.
// URL of the original image.
val url = "https://t1.kakaocdn.net/kakaocorp/Service/KakaoTalk/pc/slide/talkpc_theme_01.jpg"
// Upload an image to the Kakao image server.
LinkClient.rx.scrapImage(url)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ imageUploadResult ->
Log.i(TAG, "Succeeded in scraping an image. \n${imageUploadResult.infos.original}")
}, { error ->
Log.e(TAG, "Failed to scrape an image.", error)
}).addTo(disposables)
When the request is successful, the information of the uploaded image is returned. You can use the image URL when configuring a message.
Name | Type | Description | Required |
---|---|---|---|
infos | ImageInfos |
The uploaded image information. | O |
Name | Type | Description | Required |
---|---|---|---|
original | ImageInfo |
The original image information. | O |
Name | Type | Description | Required |
---|---|---|---|
url | String |
URL of the uploaded image. | O |
contentType | String |
Format of the uploaded image. | O |
length | Number |
File size of the uploaded image in bytes. | O |
width | Number |
Width of the uploaded image in pixels. | O |
height | Number |
Height of the uploaded image in pixels. | O |
To see how to use the Messaging API using the Legacy Kakao SDK for Android, click this button. It is highly recommended to migrate to the new version of Android SDK as soon as possible because the Legacy version may not be supported anymore. The Legacy guide is not provided in the English version. Refer to the original Korean documentation.