페이지 이동경로
  • 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 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
Reference App setting
[SDK, RxSDK] shareDefault()
[SDK] isKakaoTalkSharingAvailable()
[SDK] makeDefaultUrl()
[SDK] SharingResult
Install
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms - -

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.

Request

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.

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.

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)

Send message with custom template

Basic information
Reference App setting
[SDK, RxSDK] shareCustom()
[SDK] isKakaoTalkSharingAvailable()
[SDK] SharingResult
[SDK] makeCustomUrl()
Install
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms
Message Template
- -

This API enables you to customize a template in [Tools] > [Message Template Builder] and send a message through Kakao Talk.

Request

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.

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.

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)

Send scrape message with default template

Basic information
Reference App setting
[SDK, RxSDK] shareScrap()
[SDK] isKakaoTalkSharingAvailable()
[SDK] makeScrapUrl()
[SDK] SharingResult
Install
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms - -

This API scrapes a web page, configures a message based on the scraped web page information, and then sends it through Kakao Talk.

Request

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.

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.

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)

Send scrape message with custom template

Basic information
Reference App setting
[SDK, RxSDK] shareScrap()
[SDK] isKakaoTalkSharingAvailable()
[SDK] makeScrapUrl()
[SDK] SharingResult
Install
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms
Message Template
- -

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.

Request

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.

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.

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)

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. You cannot use the system reserved words CHAT_TYPE, HASH_CHAT_ID and TEMPLATE_ID as keys for the serverCallbackArgs. The key is included in the notification with the value defined in the specification of Kakao Talk Sharing success callback.

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

Basic information
Reference App setting
[SDK, RxSDK] uploadImage()
[SDK, RxSDK] scrapImage()
[SDK] ImageUploadResult
Install
Initialize
Permission Prerequisite Kakao Login User consent
- Register platforms - -

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.

Sample

Upload image
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)
Scrape image
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)

See more