我尝试使用"openFileOutput“保存一个图像文件,然后使用EXTRA_STREAM将该文件添加到我的意图中。但是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."));更新的代码
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."));
}发布于 2010-12-28 12:30:41
因此,只需做一件事,而不是使用R.drawable.NameOfTheImage直接命名。
https://stackoverflow.com/questions/4543540
复制相似问题