chand mohd
chand mohd

Reputation: 2550

Share multiple image urls to other application

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.

Upvotes: 2

Views: 2905

Answers (2)

chand mohd
chand mohd

Reputation: 2550

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()
            }
        }

    }

Upvotes: 5

Rajat Kumar Tyagi
Rajat Kumar Tyagi

Reputation: 116

Please try with this code

Uri uri1 = Uri.parse("https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823_960_720.jpg");
Uri uri2 = Uri.parse("https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823_960_720.jpg");
Uri uri3 = Uri.parse("https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823_960_720.jpg");

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("image/*"); /* This example is sharing jpeg images. */

ArrayList<Uri> files = new ArrayList<Uri>();
files.add(uri1);
files.add(uri2);
files.add(uri3);

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(Intent.createChooser(intent , "Share image");

Upvotes: 0

Related Questions