E / JavaBinder:!!!绑定交易失败!!!使用FileProvider

时间:2019-02-28 23:22:57

标签: android android-fileprovider parcel

我正在尝试从视图生成图像,将其保存然后共享。 我正在使用Fileprovider,但仍然出现著名的错误:

  

E / JavaBinder:!!!绑定交易失败!!! (包裹大小=   728232)D / AndroidRuntime:关闭VM E / AndroidRuntime:FATAL   例外:主要       流程:com.blagues.agogo,PID:18150       java.lang.RuntimeException:android.os.TransactionTooLargeException:数据包大小728232字节

这是我的代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_shareable_img, container, false);

    ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.preview);
    li = (RelativeLayout) view.findViewById(R.id.li);
    li.getLayoutParams().width = 720;
    li.getLayoutParams().height = 980;
    li.requestLayout();
    quote = getArguments().getString("quote");
    qText = (TextView) view.findViewById(R.id.qText);
    extra = (TextView) view.findViewById(R.id.extra);
    Typeface fontQuote = Typeface.createFromAsset(getActivity().getAssets(),
            "fonts/Roboto-Regular.ttf");
    qText.setTypeface(fontQuote);
    qText.setTextSize(12);
    qText.setText(quote);
    setBackground(li);

    fab = (FloatingActionButton) view.findViewById(R.id.floatingActionButton);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            doShare();
        }
    });

    return view;
}


public void doShare() {

    Bitmap bitmap = getBitmapFromView(li);

    try {
        File file = new File(Environment.getExternalStorageDirectory(),"bgpic1.jpeg");
        FileOutputStream fOut = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
        fOut.flush();
        fOut.close();
        file.setReadable(true, true);
        final Intent intent = new Intent(Intent.ACTION_SEND);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID , file));
        }else{
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        }
        intent.putExtra(Intent.EXTRA_TEXT,getString(R.string.share_via));
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setType("image/*");
        Intent chooser = Intent.createChooser(intent,"Partager..");
        startActivity(intent);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

public void setBackground(View view) {

    view.setBackgroundResource(R.drawable.bg3);

}

private Bitmap getBitmapFromView(View view) {
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {

        bgDrawable.draw(canvas);
    } else {

        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return returnedBitmap;
}

你知道我错过了什么吗?

谢谢

0 个答案:

没有答案