与其他人

时间:2017-12-29 15:31:24

标签: android image transactions share large-data

有时,应用会在与其他应用分享图片时收到android.os.TransactionTooLargeException。代码不是传递图片本身而是传递URI。

第一次崩溃后,可以多次重复相同的过程而不会出现问题。

错误android.os.TransactionTooLargeException也不具体,以确定问题的确切位置。

有没有办法进一步调试此错误? 如何解决?

提前感谢您的帮助。

private void sharePicture() {

    BitmapDrawable draw = (BitmapDrawable) mIvPicture.getDrawable();
    Bitmap bitmap = draw.getBitmap();

    FileOutputStream outStream = null;
    File sdCard = Environment.getExternalStorageDirectory();
    File dir = new File(sdCard.getAbsolutePath() + "/DogWalkTracker");
    dir.mkdirs();
    String fileName = String.format("%d.jpg", System.currentTimeMillis());
    File outFile = new File(dir, fileName);

    try {
        outStream = new FileOutputStream(outFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
        outStream.flush();
        outStream.close();
    } catch (Exception ex) {
        Toast.makeText(mContext, R.string.msgErrorPicture3, Toast.LENGTH_LONG).show();
        return;
    }

    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    intent.setData(Uri.fromFile(outFile));
    getActivity().sendBroadcast(intent);

    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outFile));
    shareIntent.setType("image/jpeg");
    startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.msgSelectApp)));    
}
  

12-29 12:59:21.779 15450-15450 / br.com.cfb.dogwalktrackeruser E / JavaBinder:!!!失败的粘合剂交易! (包裹尺寸= 667052)           12-29 12:59:21.781 15450-15450 / br.com.cfb.dogwalktrackeruser D / AndroidRuntime:关闭VM           12-29 12:59:21.786 15450-15450 / br.com.cfb.dogwalktrackeruser E / AndroidRuntime:FATAL EXCEPTION:main                                                                                          处理:br.com.cfb.dogwalktrackeruser,PID:15450                                                                                          java.lang.RuntimeException:android.os.TransactionTooLargeException:数据包大小667052字节                                                                                              在android.app.ActivityThread $ StopInfo.run(ActivityThread.java:3776)                                                                                              在android.os.Handler.handleCallback(Handler.java:751)                                                                                              在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                              在android.os.Looper.loop(Looper.java:154)                                                                                              在android.app.ActivityThread.main(ActivityThread.java:6123)                                                                                              at java.lang.reflect.Method.invoke(Native Method)                                                                                              在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)                                                                                              在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)                                                                                           引起:android.os.TransactionTooLargeException:数据包大小为667052字节                                                                                              在android.os.BinderProxy.transactNative(原生方法)                                                                                              在android.os.BinderProxy.transact(Binder.java:615)                                                                                              在android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3700)                                                                                              在android.app.ActivityThread $ StopInfo.run(ActivityThread.java:3768)                                                                                              在android.os.Handler.handleCallback(Handler.java:751)                                                                                              在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                              在android.os.Looper.loop(Looper.java:154)                                                                                              在android.app.ActivityThread.main(ActivityThread.java:6123)                                                                                              at java.lang.reflect.Method.invoke(Native Method)                                                                                              在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)                                                                                              在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

1 个答案:

答案 0 :(得分:0)

我测试了应用程序并确定在我发布的代码执行后以及在onSaveInstanceState之后发生了错误,所以我查看了启动其他应用程序的片段,并注意到我正在向片段传递图片和其他数据

我刚刚将图片Uri传递给片段,问题解决了。