I implemented a share button(code is written in Kotlin
) which already can send text to whatsapp / email etc.
Now I also want to send an image, but after trying several tutorials, it still displays the same error:
Instead of the picture "image27.png", only an undefined broken file "2131099738" is send.
Here is my code:
package com.example.myapp
...
share_button.setOnClickListener {
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.type = "image/png"
val shareImageURI = Uri.parse("android.resource://com.example.myapp/drawable/"+R.drawable.image27)
val shareSub = "This is for you"
val shareBody = message
shareIntent.putExtra(Intent.EXTRA_STREAM, shareImageURI)
shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareSub)
shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody)
startActivity(Intent.createChooser(shareIntent, "Share this"))
}
The picture is saved here: C:\Users\Bine\AndroidStudioProjects\MyApp\app\src\main\res\drawable\image27.png
How can I fix this?