android 系统分享的微信报错获取资源失败 您所在的位置:网站首页 获取资源失败无法享受朋友圈 android 系统分享的微信报错获取资源失败

android 系统分享的微信报错获取资源失败

2024-07-13 01:32| 来源: 网络整理| 查看: 265

项目场景:

andoird 调用系统分享-点击微信分享获取资源失败

问题描述:

andoird 调用系统分享-点击微信分享获取资源失败 调起系统分享的代码:

Intent intent = new Intent(Intent.ACTION_SEND); if (jsonObject.has("image") && !TextUtils.isEmpty(jsonObject.optString("image"))) { intent.setType("image/*"); //分享图片 byte[] bytes = Base64.decode(jsonObject.optString("image"), Base64.NO_WRAP); Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); if (bitmap != null) { String fileUrl = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, null, null); if(TextUtils.isEmpty(fileUrl)){// 插入系统相册失败时保存文件 upd 2019-04-13 19:00:41 fileUrl = saveFile(bitmap,100); } final Uri fileUri = Uri.parse(fileUrl); intent.putExtra(Intent.EXTRA_STREAM, fileUri); //传输图片或者文件 采用流的方式 } } else { intent.setType("text/plain");//分享文本 } String content=null; if (jsonObject.has("title") && !TextUtils.isEmpty(jsonObject.optString("title"))) { intent.putExtra(Intent.EXTRA_TITLE, jsonObject.optString("title")); intent.putExtra(Intent.EXTRA_SUBJECT, jsonObject.optString("title")); content=jsonObject.optString("title"); } if (jsonObject.has("url") && !TextUtils.isEmpty(jsonObject.optString("url"))) { content+=jsonObject.optString("url"); intent.putExtra(Intent.EXTRA_TEXT,content); //附带的说明信息 intent.putExtra("Kdescription", content); }else{ intent.putExtra("Kdescription",content); } startActivity(Intent.createChooser(intent, "分享到")); 原因分析:

这样写时调起系统分享,点击微信分享时会弹出资源获取失败的toast

解决方案:

这样写时调起系统分享,点击微信分享时会弹出资源获取失败的toast

解决方案为:添加两句代码 Intent最好加上这个flag,intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 在分享文本等的时候必须加上intent.putExtra(Intent.EXTRA_TEXT,content);



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有