小编Kar*_*eli的帖子

即使文件大小超小,TransactionTooLargeException也是如此

尝试共享图像文件时,我不断收到此错误:

java.lang.RuntimeException:android.os.TransactionTooLargeException:数据包大小1085992字节

我假设一个解决方案是将图像压缩得更多,这会减小尺寸.这是完成这项工作的功能:

 public static File saveBitmaptoFile(Bitmap bitmap, File pictureFile) {
    FileOutputStream out = null;
    try {
        out = new FileOutputStream(pictureFile);

        // on the next line I'm trying compress the heck out of image.
        bitmap.compress(Bitmap.CompressFormat.JPEG, 1, out);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return pictureFile;
}
Run Code Online (Sandbox Code Playgroud)

这是共享功能:

 private void shareToInstagram() {
        String type = "image/png";
        Intent share = new Intent(Intent.ACTION_SEND); …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-sharing

0
推荐指数
1
解决办法
5120
查看次数

标签 统计

android ×1

android-intent ×1

android-sharing ×1