"The File is not supported" error for sharig a video using Whatsapp share

Viewed 33

I am using the code to share in an Mp4 video in WhatsApp

  private fun shareVideoToApp(context: Context, packageName: String) {
        sharePath?.let { path ->
            val file = File(path)

            startActivity(Intent().apply {
                action = Intent.ACTION_SEND
                setPackage(packageName)
                putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(context, context.packageName + ".provider", file))
                type = "video/*"
                addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            })
        } ?: run {
            Log.e(TAG, "Path is null")
        }

    }

The share path variable has value

/storage/emulated/0/Android/data/com.sample.androidapp/files/Download/VideoSnippets/1632536010_0_9265.mp4
1 Answers

Sharing is pretty messed up after fileproviders and newer android versions Try androidx sharecompat lib which is already included if u use androidx

new ShareCompat
                .IntentBuilder(context)
                .setType("video/*")
                .setStream(uri)
                .setText("Desired text to share")
                .startChooser();
Related