gpt4 book ai didi

java - 为什么发送 Bitmap 时崩溃

转载 作者:行者123 更新时间:2023-12-01 17:36:07 26 4
gpt4 key购买 nike

我正在尝试通过发送位图来共享图像。我发现的解决方案适用于 Android 10.0 的模拟器,但不适用于 Android 7.0(也不适用于运行 Android 9 的 LG V20),它会崩溃。

这是我当前的代码。知道如何避免崩溃吗?预先感谢您的帮助。

            picIV.buildDrawingCache();
Bitmap bitmap = picIV.getDrawingCache();

String path = MediaStore.Images.Media.insertImage(getContentResolver(),
bitmap, "Challengers", null);

Uri uri = Uri.parse(path);

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
//share.putExtra(Intent.EXTRA_TEXT, "I found something cool!");
startActivity(Intent.createChooser(share, "Share Your Design!"));

运行此行时似乎发生了崩溃

            Uri uri = Uri.parse(path);

最佳答案

也许您的路径null?你调试了吗?

从方法Uri.parse(...)的源代码中,我注意到如果它采用null作为参数并且MediaStore,它会返回一个错误.Images.Media.insertImage(...) 返回 null“如果图像因任何原因未能存储”。

关于java - 为什么发送 Bitmap 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61036518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com