Thiago Carvalho
Thiago Carvalho

Reputation: 105

How to share a recorded video programmatically?

Well guys, I'm new at programming, I've tried some ways, but I was not able to achieve it.

I have these two paths, how can I open the share options to send this file?

I/ExternalStorage: Scanned /storage/emulated/0/Movies/HD2022-04-23-22-37-44.mp4:
I/ExternalStorage: -> uri=content://media/external_primary/video/media/102870

I did it with text, but I was not able to do it with the video, it's something like this?

binding.btShare.setOnClickListener {
            ShareCompat.IntentBuilder(this)
                .setType("text/plain")
                .setChooserTitle(R.string.shareFriends)
                .setText(getString(R.string.shareMessage)+" https://play.google.com/store/apps/details?id=" + this.getPackageName())
                .startChooser();
        }

Upvotes: 1

Views: 67

Answers (1)

Thiago Carvalho
Thiago Carvalho

Reputation: 105

No more need. thx... Already did. I'll put it here, maybe it can help someone.

 fun shareVideo(filePath:String) {

        val videoFile = File(filePath)
        val videoURI = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            FileProvider.getUriForFile(this,BuildConfig.APPLICATION_ID + ".fileprovider", videoFile)
        else
            Uri.fromFile(videoFile)
        ShareCompat.IntentBuilder.from(this)
            .setStream(videoURI)
            .setType("video/mp4")
            .setChooserTitle("Share video...")
            .startChooser()
    }

Upvotes: 1

Related Questions