Search code examples
androidandroid-developer-api

Send thumbnail with text - no app can perform this action - error


I would like to display a small preview image of my content to be shared. However, when I run the code, I get a message that no app can perform this action. Unfortunately I don't know what's wrong

    private fun shareContentWithPreview() {
    val share = Intent.createChooser(Intent().apply {
        action = Intent.ACTION_SEND
        putExtra(Intent.EXTRA_TEXT, "https://developer.android.com/training/sharing/")
        type = "image/jpg"
        // (Optional) Here we're setting the title of the content
        putExtra(Intent.EXTRA_TITLE, "Introducing content previews")

        // (Optional) Here we're passing a content URI to an image to be displayed
        val uri: Uri = Uri.parse("android.resource://com.one.myapplication/drawable/rome.jpg")

        data = uri


        flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
    }, null)
    startActivity(Intent.createChooser(share, null))
}

Solution

  • Hi m8 think you are passing putExtra(Intent.EXTRA_TEXT, ...), and you should pass putExtra(Intent.EXTRA_STREAM, ...) if you a re passing a Uri