[英]Android FileOutputStream
i am attempting to save an image file using "openFileOutput" and then adding that file to my intent with EXTRA_STREAM. 我试图使用“ openFileOutput”保存图像文件,然后使用EXTRA_STREAM将该文件添加到我的意图中。 but logcat keeps saying that file size is 0, i have the proper permission in my manifest.
但是logcat一直说文件大小为0,我在清单中有适当的权限。
FileOutputStream fos = openFileOutput("p001.jpg", Context.MODE_WORLD_READABLE);
File jpg = getFileStreamPath("p001.jpg");
fos.close();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_SUBJECT, "Fail picture");
share.putExtra(Intent.EXTRA_TEXT, "Epic fail!!!");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(jpg));
startActivity(Intent.createChooser(share, "Choose share method."));
updated code 更新的代码
private void HandleSMS() throws IOException {
FileOutputStream fos = openFileOutput(R.drawable.p001, Context.MODE_WORLD_READABLE);
File jpg = getFileStreamPath("p001.jpg");
fos.close();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_SUBJECT, "Fail picture");
share.putExtra(Intent.EXTRA_TEXT, "Epic fail!!!");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(jpg));
startActivity(Intent.createChooser(share, "Choose share method."));
}
因此,请使用R.drawable.NameOfTheImage
而不是直接名称来做一件事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.