Search code examples
androidkotlinandroid-tvandroid-sharing

Share URI/Text on Android TV displays Turn on Bluetooth Dialog


I want to share an image with other apps in my Android TV application. I upload the image when the user clicks on a button and I want to share its URL (as text) or URI. So, this is my code:

val bitmap = ......
btnAccept.setOnClickListener {
            val userId = Storage.getInstance(playerView.context).getUserId()
            vm.storeImageInDatabase(userId, bitmap, ::onImageUploadedSuccessfully)
        }

private fun onImageUploadedSuccessfully(url: String) {
        val sendIntent: Intent = Intent().apply {
            action = Intent.ACTION_SEND
            putExtra(Intent.EXTRA_TEXT, url)
            type = "text/plain"
        }
        startActivity(Intent.createChooser(sendIntent, "Share"))
    }

I have even changed onImageUploadedSuccessfully() to the following method in order to share the URI.

private fun onImageUploadedSuccessfully(url: String) {
        val sendIntent: Intent = Intent().apply {
            action = Intent.ACTION_SEND
            putExtra(Intent.EXTRA_STREAM, Uri.parse(url))
            type = "image/jpg"
        }
        startActivity(Intent.createChooser(sendIntent, "Share"))
    }

However, the result is the same. Following Dialog displays and ask me to enable the Bluetooth. I click on TURN ON button but nothing happens. This dialogue displays again and again whenever my upload is successful. Therefore, I am unable to share anything.

Any idea if sharing on TV app is different than the mobile app?

enter image description here


Solution

  • Depending on the type of URI you want to share with other apps you might have to search into their developer's sites, given that an application should have intent filters accepting data from outside apps.

    Let's out the same scenario for your app, if you develop your application to do not receive any data from outside your app the

    Intent.createChooser 
    

    will never show your app in the options to share.

    https://developer.android.com/guide/components/intents-filters.html