Search code examples
androidkotlinandroid-intentintentfilterandroid-sharing

Can i confirm app user did share my app link with Intent.ACTION_SEND?


In my app i have a "Share App Link" button which when clicked shares app play store link in Social Media Apps (WhatsApp, Instagram, Twitter) using Intent.ACTION_SEND and gives user a prize for this action. But I can't confirm if user successfully shared the link in the Social Media Apps because Intent.ACTION_SEND doesn't have any return. What can i do about this situation ? I am also open to other ideas then confirmation or usage of another intent filter.

My code for this is:

fun shareAppLink(view: View){
        val shareIntent = Intent(Intent.ACTION_SEND)
        shareIntent.type = "text/plain"
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name))
        var shareMessage = "\nLet me recommend you this application\n\n"
        shareMessage = """${shareMessage}https://play.google.com/store/app/details?id=${this.packageName}""".trimIndent()
        shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage)
        var whiteList=mutableListOf("com.whatsapp","com.instagram.android","com.twitter.android")
        startActivity(CustomChooserIntent.create(packageManager,shareIntent,"",whiteList))

CustomChooserIntent uses a whitelist to allow which apps can be chosen.


Solution

  • Sorry, that's not possible. You're correct about the reason: there's no return value. It wouldn't be possible to have a sensible return value across all possible methods of sharing—for example, what if they saved it as a draft in their email client to send later?

    If you want to confirm that the user actually shared something, you could always use app-specific APIs (e.g., this API for Twitter) that would allow you to share the post from within your app. Of course, don't forget that there's nothing stopping the user from deleting the post immediately after posting it :-)