add image to twitter share intent android

后端 未结 3 1959
执念已碎
执念已碎 2021-02-08 10:42

I\'m trying to add an image to my twitter share intent. I save an image locally in one class and then in another I get the image and try to attach to my intent.

Here is

3条回答
  •  后悔当初
    2021-02-08 11:16

    Here is solution:

    private fun shareOnTwitter() {
        val file = File(context!!.filesDir, FILENAME_SHARE_ON_TWITTER)
        val uriForFile = FileProvider.getUriForFile(context!!, com.yourpackage.activity.YourActivity, file)
    
        val intent = Intent(Intent.ACTION_SEND).apply {
            type = "image/jpeg"
            putExtra(Intent.EXTRA_STREAM, uriForFile)
        }
        startActivity(intent)
    }
    

提交回复
热议问题