Share Image to third party apps in android

Viewed 58

I'm trying to share image with third party apps in android. I'm able to share image with all device except Xiaomi(Android 12) & OnePlus Node (Android 11).

 val shareIntent = Intent()
 shareIntent.action = Intent.ACTION_SEND
 shareIntent.putExtra(Intent.EXTRA_TEXT, shareText)
 shareIntent.putExtra(Intent.EXTRA_STREAM,imageUri)
 shareIntent.type = "image/*"
 shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
 context.startActivity(Intent.createChooser(shareIntent, "Share using"))

Shows toast message --> this file is not supported.

1 Answers
    val file = File(path, "${System.currentTimeMillis()}.png")
    file.outputStream().use {                 
           imageBitmap!!.compress(Bitmap.CompressFormat.PNG,100, it)
                }
    var imageUri = FileProvider.getUriForFile(
                    context,
                    BuildConfig.APPLICATION_ID + ".fileprovider",
                    file )
Related