我在三星Galaxy Nexus上使用Android 4.03。日志显示该文件已写入手机内存,但是当我在Windows资源管理器中检查或使用手机库时,我看不到我刚刚拍摄的图像。
这是我的代码。
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = mExternalStorageWriteable = true;
Log.d(TAG, "Can Write ");
try {
outStream = new FileOutputStream(String.format("/sdcard/myfile.jpg", System.currentTimeMillis()));
outStream.write(data);
outStream.close();
Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
Log.d(TAG, "Cant Write ");
} else {
// Something else is wrong. It may be one of many other states, but all we need
// to know is we can neither read nor write
mExternalStorageAvailable = mExternalStorageWriteable = false;
Log.d(TAG, "Other Error ");
}
}
};
答案 0 :(得分:6)
尝试使用
Environment.getExternalStorageDirectory()
而不是“/ sdcard”。