【发布时间】:2013-12-17 01:00:32
【问题描述】:
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
// Write to SD Card
fileName = String.format("%d.jpg", System.currentTimeMillis());
File file = new File(Environment.getExternalStorageDirectory().getPath()+"/camtest");
if(!file.exists())
file.mkdirs();
File outputFile = new File(file, fileName);
outStream = new FileOutputStream(outputFile);
outStream.write(data);
outStream.close();
Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
resetCam();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Log.d(TAG, "onPictureTaken - jpeg");
}
};
使用此代码,我可以存储到设备存储中。
DeviceStorage/Emulated/0/camtest
我想将它存储到外部 SD 卡上。我该怎么做
我有以下权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
【问题讨论】:
-
在测试时确保设备没有通过 USB 植根。
-
嗨@Hank 不,我的设备没有root
-
它是否记录 writeBytes 行?
-
是的@superfell 它确实也记录了 writeBytes 行的大小
-
@superfell 我也可以访问从文件管理器写入的文件
标签: android file-io storage android-sdcard