페이지 이동경로
  • Docs>
  • Message>
  • Kakao Talk Sharing: Android

Message

Kakao Talk Sharing: Android

This document describes how to integrate the Kakao Talk Sharing APIs into your service with the Kakao SDK for Android ("Android SDK").

Before you begin

Add modules

To use the Kakao Talk Sharing, you need to add v2-share(Kakao Talk Sharing module) that provides ShareClient in the module-level build.gradle.kts file by referring to Add modules.

Note

In Android SDK 2.11.0, the names of the module, classes, and methods related to Kakao Talk Sharing have been changed due to the change of its service name. To see more detailed changes, see Version history.

Add queries

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.

Choose an API to use

According to your service's purpose and requirements, you need to decide which API to use first by considering their characteristics and difference.

1. Select a type of Messaging API

There are two types of messaging APIs: the Kakao Talk Sharing API and the Kakao Talk Messaging API. You need to understand the differences between the two messaging APIs completely by referring to Concepts, and decide which API to use to implement the function to send a message.

2. Select a message type and configuration method

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 How to use 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.

Set Custom URL Scheme

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}

Configure a message

When you configure a Kakao Talk message through the Kakao Talk Sharing 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.

Feed
List
Location
Commerce
Text
Calendar
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 Talk Sharing, 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"
    )
)
val defaultCalendar = CalendarTemplate(
    idType = IdType.EVENT,
    id = "${YOUR_EVENT_ID}",
    content = Content(
        title = "Fashion show for S/S collection",
        description = "Join this upcoming event! To add this event to your calendar, click [일정 등록 하기].",
        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",
        )
    ),
    buttons = listOf(
        Button(
            title = "View event",
            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.

1. Figure out template components

Check which object you should create for a Feed message by referring to Message template > Feed message. Feed message is defined as the FeedTemplate class.

2. Define template components

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.

3. Request to send a message

Pass the FeedTemplate object created in Step 2 when calling the Kakao Talk Sharing or Kakao Talk Messaging API.

Send message with default template

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms - - Common
isKakaoTalkSharingAvailable()
SharingResult
makeDefaultUrl()
Android SDK
shareDefault()
ReactiveX Android SDK
shareDefault()

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 isKakaoTalkSharingAvailable() that checks if Kakao Talk has been installed. If Kakao Talk is installed, call shareDefault() that shares a message through Kakao Talk. If not installed, call makeDefaultUrl() in the WebSharerClient class to declare a URL for sharing and open the URL WebView or a default browser.

Parameter

Name Type Description Required
context Context Refer to Context. O
shareDefault DefaultTemplate Object of the message template to be sent.
Use one of the following templates:
FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
CalendarTemplate
You must create an object of the class for the desired template by referring 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 Talk Sharing success callback.
X

Sample

Kotlin
RxKotlin
// Send a Feed message.

// Check if Kakao Talk has been installed.
if (ShareClient.instance.isKakaoTalkSharingAvailable(context)) {    
    // Kakao Talk Sharing is available.
    ShareClient.instance.shareDefault(context, defaultFeed) { sharingResult, error ->
    if (error != null) {
        Log.e(TAG, "Kakao Talk Sharing failed.", error)
    }
    else if (sharingResult != null) {
        Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
        startActivity(sharingResult.intent)

        // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
        Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
        Log.w(TAG, "Argument Msg: ${sharingResult.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.makeDefaultUrl(defaultFeed)

    // Open URI in custom tabs.

    // 1. Open URI on the browser that supports custom tabs. (Example: Chrome, Samsung internet, FireFox, Whale, etc)
    try {
        KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
    } catch(e: UnsupportedOperationException) {
        // Handle exception that occurs when any browser that supports custom tabs is installed on user's device. 
    }

    // 2. Open URI on the browser that does not support custom tabs. (Example: Daum, Naver, etc)
    try {
        KakaoCustomTabsClient.open(context, sharerUrl)
    } catch (e: ActivityNotFoundException) {
        // Handle exception that occurs when any web browser is not installed on user's device.
    }
}
var disposables = CompositeDisposable()

// Send a Feed message.
ShareClient.rx.shareDefault(context, defaultFeed)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({ sharingResult ->
        Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
        startActivity(sharingResult.intent)

        // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
        Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
        Log.w(TAG, "Argument Msg: ${sharingResult.argumentMsg}")
    }, { error ->
        Log.e(TAG, "Kakao Talk Sharing failed.", error)
    })
    .addTo(disposables)

Calling shareDefault() 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.

shareDefault() returns SharingResult. Because the Kakao Talk Sharing API does not inform the result of message delivery, implement the Kakao Talk Sharing success callback function.

SharingResult
Name Type Description Required
intent Intent Intent to invoke Kakao Talk Sharing with the requested template. O
argumentMsg Map<String, String> Result of templateArgs validation. O
warningMsg Map<String, String> Result of template validation. O

Send message with custom template

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms
Message Template
- - Common
isKakaoTalkSharingAvailable()
SharingResult
makeCustomUrl()
Android SDK
shareCustom()
ReactiveX Android SDK
shareCustom()

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 isKakaoTalkSharingAvailable() that checks if Kakao Talk has been installed. If Kakao Talk is installed, call shareCustom() that shares a message through Kakao Talk. If not installed, call makeCustomUrl() in the WebSharerClient class to declare a URL for sharing and open the URL WebView or a default browser.

Parameter

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 scrape 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 Talk Sharing success callback.
X

Sample

Kotlin
RxKotlin
// 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 (ShareClient.instance.isKakaoTalkSharingAvailable(context)) {    
    // Kakao Talk Sharing is available.
    ShareClient.instance.shareCustom(context, templateId) { sharingResult, error ->
        if (error != null) {
            Log.e(TAG, "Kakao Talk Sharing failed.", error)
        }
        else if (sharingResult != null) {
            Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
            startActivity(sharingResult.intent)

            // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
            Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
            Log.w(TAG, "Argument Msg: ${sharingResult.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.makeCustomUrl(templateId)

    // Open URI in custom tabs.

    // 1. Open URI on the browser that supports custom tabs. (Example: Chrome, Samsung internet, FireFox, Whale, etc)
    try {
        KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
    } catch(e: UnsupportedOperationException) {
        // Handle exception that occurs when any browser that supports custom tabs is installed on user's device.
    }

    // 2. Open URI on the browser that does not support custom tabs. (Example: Daum, Naver, etc)
    try {
        KakaoCustomTabsClient.open(context, sharerUrl)
    } catch (e: ActivityNotFoundException) {
        // Handle exception that occurs when any web browser is not installed on user's device.
    }
}
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

ShareClient.rx.shareCustom(context, templateId)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({ sharingResult ->
        Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
        startActivity(sharingResult.intent)

        // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
        Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
        Log.w(TAG, "Argument Msg: ${sharingResult.argumentMsg}")
    }, { error ->
        Log.e(TAG, "Kakao Talk Sharing failed.", error)
    })
    .addTo(disposables)

Calling shareCustom() 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.

shareCustom() returns SharingResult. Because the Kakao Talk Sharing API does not inform the result of message delivery, implement the Kakao Talk Sharing success callback function.

Send scrape message with default template

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms - - Common
isKakaoTalkSharingAvailable()
SharingResult
makeScrapUrl()
Android SDK
shareScrap()
ReactiveX Android SDK
shareScrap()

This API scrapes 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 isKakaoTalkSharingAvailable() that checks if Kakao Talk has been installed. If Kakao Talk is installed, call shareScrap() that shares a message through Kakao Talk. If not installed, call makeScrapUrl() in the WebSharerClient class to declare a URL for sharing and open the URL WebView or a default browser.

Parameter

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 Talk Sharing success callback.
X

Sample

Kotlin
RxKotlin
// 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 (ShareClient.instance.isKakaoTalkSharingAvailable(context)) {    
    // Kakao Talk Sharing is available.
    ShareClient.instance.shareScrap(context, url) { sharingResult, error ->
        if (error != null) {
            Log.e(TAG, "Kakao Talk Sharing failed.", error)
        }
        else if (sharingResult != null) {
            Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
            startActivity(sharingResult.intent)

            // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
            Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
            Log.w(TAG, "Argument Msg: ${sharingResult.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.makeScrapUrl(url)

    // Open URI in custom tabs.

    // 1. Open URI on the browser that supports custom tabs. (Example: Chrome, Samsung internet, FireFox, Whale, etc)
    try {
        KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
    } catch(e: UnsupportedOperationException) {
        // Handle exception that occurs when any browser that supports custom tabs is installed on user's device. 
    }

    // 2. Open URI on the browser that does not support custom tabs. (Example: Daum, Naver, etc)
    try {
        KakaoCustomTabsClient.open(context, sharerUrl)
    } catch (e: ActivityNotFoundException) {
        // Handle exception that occurs when any web browser is not installed on user's device.
    }
}
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"

ShareClient.rx.shareScrap(context, url)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({ sharingResult ->
        Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
        startActivity(sharingResult.intent)

        // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
        Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
        Log.w(TAG, "Argument Msg: ${sharingResult.argumentMsg}")
    }, { error ->
        Log.e(TAG, "Kakao Talk Sharing failed.", error)
    })
    .addTo(disposables)

Calling shareScrap() 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.

shareScrap() returns SharingResult. Because the Kakao Talk Sharing API does not inform the result of message delivery, implement the Kakao Talk Sharing success callback function.

Send scrape message with custom template

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms
Message Template
- - Common
isKakaoTalkSharingAvailable()
SharingResult
makeScrapUrl()
Android SDK
shareScrap()
ReactiveX Android SDK
shareScrap()

This API scrapes 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 scrape message.

To figure out if it is possible to share a message through Kakao Talk, call isKakaoTalkSharingAvailable() that checks if Kakao Talk has been installed. If Kakao Talk is installed, call shareScrap() that shares a message through Kakao Talk. If not installed, call makeScrapUrl() in the WebSharerClient class to declare a URL for sharing and open the URL WebView or a default browser.

Parameter

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 scrape 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 specified 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 scrape 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 Talk Sharing success callback.
X

Sample

Kotlin
RxKotlin
// 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 (ShareClient.instance.isKakaoTalkSharingAvailable(context)) {    
    // Kakao Talk Sharing is available.
    ShareClient.instance.shareScrap(context, url, templateId) { sharingResult, error ->
        if (error != null) {
            Log.e(TAG, "Kakao Talk Sharing failed.", error)
        }
        else if (sharingResult != null) {
            Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
            startActivity(sharingResult.intent)

            // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
            Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
            Log.w(TAG, "Argument Msg: ${sharingResult.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.makeScrapUrl(url, templateId)

    // Open URI in custom tabs.

    // 1. Open URI on the browser that supports custom tabs. (Example: Chrome, Samsung internet, FireFox, Whale, etc)
    try {
        KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
    } catch(e: UnsupportedOperationException) {
        // Handle exception that occurs when any browser that supports custom tabs is installed on user's device. 
    }

    // 2. Open URI on the browser that does not support custom tabs. (Example: Daum, Naver, etc)
    try {
        KakaoCustomTabsClient.open(context, sharerUrl)
    } catch (e: ActivityNotFoundException) {
        // Handle exception that occurs when any web browser is not installed on user's device.
    }
}
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"

ShareClient.rx.shareScrap(context, url, templateId)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({ sharingResult ->
        Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
        startActivity(sharingResult.intent)

        // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
        Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
        Log.w(TAG, "Argument Msg: ${sharingResult.argumentMsg}")
    }, { error ->
        Log.e(TAG, "Kakao Talk Sharing failed.", error)
    })
    .addTo(disposables)

Calling shareScrap() 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.

shareScrap() returns SharingResult. Because the Kakao Talk Sharing API does not inform the result of message delivery, implement the Kakao Talk Sharing success callback function.

Set Kakao Talk Sharing success callback

The Kakao Talk Sharing success callback is a function to send a callback request to the URL specified on Kakao Developers when a Kakao Talk Sharing message is successfully sent to friends or a chatroom selected by a user. This function is only available for Kakao Talk Sharing API, not for Kakao Talk Messaging API.

To use this feature, you need to:

  1. Set the callback URL and request method by referring to Prerequisites > Set Kakao Talk Sharing success callback.
  2. Build a server to receive a Kakao Talk Sharing success callback.
  3. Set a custom parameter to pass additional information when requesting the Kakao Talk Sharing API.
  4. Implement a process to handle the callback delivered to your service server's callback URL.

To use the Kakao Talk Sharing callback function, you must specify a custom parameter through serverCallbackArgs. Otherwise, you cannot receive Kakao Talk Sharing success callbacks even though you registered a callback URL for Kakao Talk Sharing in [My Application]. When your service server receives a Kakao Talk Sharing 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 Talk Sharing API, declare serverCallbackArgs, and pass keys and values as a Map. Here is a code snippet showing how to set parameters for Kakao Talk Sharing success callback.

Kotlin
RxKotlin
// 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 (ShareClient.instance.isKakaoTalkSharingAvailable(context)) {    
    // Kakao Talk Sharing is available.
    ShareClient.instance.shareCustom(context, templateId, serverCallbackArgs) { sharingResult, error ->
        if (error != null) {
            Log.e(TAG, "Kakao Talk Sharing failed.", error)
        }
        else if (sharingResult != null) {
            Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
            startActivity(sharingResult.intent)

            // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
            Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
            Log.w(TAG, "Argument Msg: ${sharingResult.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.makeCustomUrl(templateId, serverCallbackArgs)

    // Open URI in custom tabs.

    // 1. Open URI on the browser that supports custom tabs. (Example: Chrome, Samsung internet, FireFox, Whale, etc)
    try {
        KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
    } catch(e: UnsupportedOperationException) {
        // Handle exception that occurs when any browser that supports custom tabs is installed on user's device. 
    }

    // 2. Open URI on the browser that does not support custom tabs. (Example: Daum, Naver, etc)
    try {
        KakaoCustomTabsClient.open(context, sharerUrl)
    } catch (e: ActivityNotFoundException) {
        // Handle exception that occurs when any web browser is not installed on user's device.
    }
}
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")

ShareClient.rx.shareCustom(context, templateId, serverCallbackArgs)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({ sharingResult ->
        Log.d(TAG, "Succeeded in Kakao Talk Sharing. ${sharingResult.intent}")
        startActivity(sharingResult.intent)

        // If you get this message even though Kakao Talk Sharing message is successfully sent, some content may not be displayed normally. 
        Log.w(TAG, "Warning Msg: ${sharingResult.warningMsg}")
        Log.w(TAG, "Argument Msg: ${sharingResult.argumentMsg}")
    }, { error ->
        Log.e(TAG, "Kakao Talk Sharing failed.", error)
    })
    .addTo(disposables)

If the Kakao Talk Sharing message is successfully sent, Kakao sends a Kakao Talk Sharing success callback including the specified parameters to the callback URL of your service server. For more information on the callback request, refer to Reference Information > Kakao Talk Sharing success callback.

Upload image

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 server or scrape it. You can only upload an image with a file size of 5 MB or less. The images uploaded to the Kakao server are stored for up to 100 days and automatically deleted after the period.

Uploading image

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms - - Common
ImageUploadResult
Android SDK
uploadImage()
ReactiveX Android SDK
uploadImage()

To upload an image, call the imageUpload() method defined in ShareClient. You can only upload an image with a file size of 5 MB or less.

Parameter

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

Sample

Kotlin
RxKotlin
// 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.
ShareClient.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 uploading 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. 
ShareClient.rx.uploadImage(file)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({ imageUploadResult ->
        Log.i(TAG, "Succeeded in uploading an image. \n${imageUploadResult.infos.original}")
    }, { error ->
        Log.e(TAG, "Failed to upload an image.", error)
    }).addTo(disposables)

Scraping image

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms - - Android SDK
scrapImage()
ReactiveX Android SDK
scrapImage()

To use an image by scraping an image uploaded on the web page, call the scrapImage() method defined in ShareClient.

Parameter

Name Type Description Required
imageUrl String URL of the image to be scraped. O
secureResource Boolean Whether to use HTTPS for the image URL scheme.
If true, HTTPS is used.
(Default: true)
X

Sample

Kotlin
RxKotlin
// 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.
ShareClient.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.
ShareClient.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.

ImageUploadResult
Name Type Description Required
infos ImageInfos The uploaded image information. O
ImageInfos
Name Type Description Required
original ImageInfo The original image information. O
ImageInfo
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

See more