android 调用系统分享微信失败:获取资源失败。
解决方案:全网仅此一家,别无分店
Intent shareIntent =new Intent();
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
shareIntent.setAction(Intent.ACTION_SEND);
ApplicationInfo applicationInfo = getApplicationInfo();
int targetSDK = applicationInfo.targetSdkVersion;
Uri uri;
if (targetSDK >= Build.VERSION_CODES.N && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(),
writeFile.getAbsolutePath(), chalkBean.getName(), null));
}else{
uri = Uri.fromFile(new File(writeFile.getPath()));
}
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "分享到:"));
该博客主要探讨了在Android应用中遇到的通过系统分享功能向微信发送图片时失败的问题。作者指出,当目标SDK版本大于等于24并且系统版本大于等于24时,需要使用特定的方法来创建Uri。解决方案包括设置Intent标志和使用MediaStore.Images.Media.insertImage()方法在Nougat及以上版本中插入图片,或者在更低版本中直接从文件创建Uri。最后,将Uri附加到分享Intent并启动分享选择器。
3846

被折叠的 条评论
为什么被折叠?



