Issue
I'm getting image urls from server now i want to share same urls to another application but its says that:
The File format is not supported
here is my code :
private fun shareImages(urls:List<String>?) {
var listOfImageUri = ArrayList<Uri>()
for (i in urls!!.indices) {
listOfImageUri.add( Uri.parse(urls[i].url))
}
val shareIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND_MULTIPLE
putParcelableArrayListExtra(Intent.EXTRA_STREAM, listOfImageUri)
type = "image/*"
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
try {
startActivity(Intent.createChooser(shareIntent, "Share Via:"))
} catch (e: ActivityNotFoundException) {
Toast.makeText(baseActivity, "No App Available", Toast.LENGTH_SHORT).show()
}
}
The link i have tried so for: share multiple images Android Share Multiple Images with Other Apps
Note: during image sharing process i do not want to save image into SD card
Please help ..Any help is Appreciated.
Solution
I'm able to send multiple images So answering my own question might help someone:
private fun convertUrlToUri(filesPath:ArrayList<ImageArray>?) {
for (i in filesPath!!.indices) {
Glide.with(this)
.asBitmap()
.load(filesPath[i].url)
.into(object : SimpleTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: com.bumptech.glide.request.transition.Transition<in Bitmap>?) {
resource.compress(Bitmap.CompressFormat.PNG, 100, ByteArrayOutputStream())
listOfUris.add(Uri.parse(MediaStore.Images.Media.insertImage(baseActivity.contentResolver, resource, "", null)))
}
})
}
}
private fun shareImages(comment:String?) {
if (listOfUris.isNotEmpty()) {
val shareIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND_MULTIPLE
type = "*/*"
putParcelableArrayListExtra(Intent.EXTRA_STREAM, listOfUris)
comment?.let {putExtra(Intent.EXTRA_TEXT,it) }
}
try {
startActivity(Intent.createChooser(shareIntent, resources.getString(R.string.share_via)))
listOfUris.clear()
} catch (e: ActivityNotFoundException) {
Toast.makeText(baseActivity, "No App Available", Toast.LENGTH_SHORT).show()
}
}
}
Answered By - chand mohd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.