cha*_*ohd 2 android uri android-intent android-contentprovider kotlin
我从服务器获取图像 url,现在我想将相同的 url 共享给另一个应用程序,但它说:
不支持该文件格式
这是我的代码:
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()
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过的链接: share multiple images Android Share Multiple Images with Other Apps
注意:在图像共享过程中我不想将图像保存到 SD 卡中
请帮助..任何帮助表示赞赏。
我可以发送多张图像因此回答我自己的问题可能会对某人有所帮助:
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()
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2657 次 |
| 最近记录: |