我有一个包含序列化对象的byte []。我试图通过.bin文件发送对象。
File f = new File(Environment.getExternalStorageDirectory().getPath(), "binary_payload.bin");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(mBinaryResponsePayload);
} catch (IOException e) {
Log.e(TAG, e, "Exception occurred while writing a binary file");
}
shareBinaryIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory().getPath() + "binary_payload.bin"));
shareBinaryIntent.setType("application/octet-stream");
startActivity(Intent.createChooser(shareBinaryIntent,
getResources().getText(R.string.appname_send_binary_button_text)));
}
}
当我尝试打印binaryString时,我得到一串1和0,但是当我尝试共享时,它说内容是空的。
谢谢!
跟进:
我尝试过greenapps建议,但我正在分享格式错误的二进制文件:
{{1}}
有什么建议吗?我真的被困了