QQ分享纯图片

分享纯图片
private fun onClickShare() {
    val params = Bundle()
    params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL,imageUrl.text.toString())
    params.putString(QQShare.SHARE_TO_QQ_APP_NAME, appName.text.toString())
    params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE);
    params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_AUTO_OPEN);
    mTencent.shareToQQ(context, params,BaseUiListener())
}
使用Glide加载获取bitmap对象并保存到本地SD卡

新版本使用kotlin编写

 Glide.with(context).load(shareEntity.transferPictureUrl).asBitmap().into(object : SimpleTarget() {
                    override fun onResourceReady(bitmap: Bitmap, glideAnimation: GlideAnimation) {
                        val localSharePicturePath=context?.let { SavePictureUtil.saveToSDCard(it,bitmap) }
                    }
                })
保存图片工具类
  /**
         * 将图片保存到SD卡
         */
        fun saveToSDCard(context: Context, bmp: Bitmap):String {
            val appDir = File(Environment.getExternalStorageDirectory(), "sina")
            if (!appDir.exists()) {
                appDir.mkdir()
            }
            val fileName = "SinaShare" + ".jpg"
            val file = File(appDir, fileName)
            if (file.exists())file.delete()
            try {
                val fos = FileOutputStream(file)
                bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos)
                fos.flush()
                fos.close()
            } catch (e: FileNotFoundException) {
                e.printStackTrace()
            } catch (e: IOException) {
                e.printStackTrace()
            }

            try {
                MediaStore.Images.Media.insertImage(context.contentResolver, file.absolutePath, fileName, null)
            } catch (e: FileNotFoundException) {
                e.printStackTrace()
            }
            return "$appDir/$fileName"
        }
备注:

6.0以上版本需要申请存储卡读写权限

QQ分享文档:

https://wiki.open.qq.com/wiki/mobile/API%E8%B0%83%E7%94%A8%E8%AF%B4%E6%98%8E#1.13_.E5.88.86.E4.BA.AB.E6.B6.88.E6.81.AF.E5.88.B0QQ.EF.BC.88.E6.97.A0.E9.9C.80QQ.E7.99.BB.E5.BD.95.EF.BC.89

你可能感兴趣的:(android开发)