【问题标题】:Image Share is not working all Google Pixel device图像共享不适用于所有 Google Pixel 设备
【发布时间】:2021-03-11 05:29:31
【问题描述】:

我正在使用 Intent 从我的应用程序中分享一张图片。它在所有设备上都可以正常工作,但是当涉及到 Google Pixel 2 XL 时,图像无法在 Skype 和 gmail 上加载。在 Gmail 上,它说:无法附加文件。这是代码sn-p

 private fun shareImageFromURI(url: String?) {
    Glide.with(this)
        .asBitmap()
        .load(url)
        .into(object : CustomTarget<Bitmap>() {
            override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                val intent = Intent(Intent.ACTION_SEND)
                intent.type = "image/*"
                intent.putExtra(Intent.EXTRA_STREAM, getBitmapFromView(resource))
                startActivity(Intent.createChooser(intent, "Share Image"))
            }

            override fun onLoadCleared(placeholder: Drawable?) {

            }
        })
}

fun getBitmapFromView(bmp: Bitmap?): Uri? {
    var bmpUri: Uri? = null
    try {
        val file = File(this.externalCacheDir, System.currentTimeMillis().toString() + ".jpg")

        val out = FileOutputStream(file)
        bmp?.compress(Bitmap.CompressFormat.JPEG, 90, out)
        out.close()
        bmpUri = Uri.fromFile(file)

    } catch (e: IOException) {
        e.printStackTrace()
    }
    return bmpUri
}

【问题讨论】:

    标签: android android-intent android-sharing


    【解决方案1】:

    试试这个解决方案:

            Glide.with(this)
            .asBitmap()
            .load(url)
            .into(object : CustomTarget<Bitmap>() {
                override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                    val imgBitmapPath = MediaStore.Images.Media.insertImage(
                        this@ImagesActivity.contentResolver,
                        resource,
                        "eVitalRx_Greetings_" + Calendar.getInstance().getTime(),
                        null
                    )
                    val imgUri = Uri.parse(imgBitmapPath)
                    val intent = Intent(Intent.ACTION_SEND)
                    intent.type = "image/*"
                    intent.putExtra(Intent.EXTRA_STREAM, imgUri)
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
                    try {
                        startActivity(Intent.createChooser(intent, ApplicationClass.languageJson?.downloadDialog?.shareImage))
                    }catch (e:Exception){
                        this@ImagesActivity.Toast("Operation Failed")
    
                    }
                }
    
                override fun onLoadCleared(placeholder: Drawable?) {
    
                }
            })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      • 2020-07-08
      相关资源
      最近更新 更多