thể trùng lặp:
Android Camera - Save image into a new folder in SD CardChụp hình với mục đích máy ảnh và lưu vào tập tin
tôi đang cố gắng để chụp hình và lưu nó vào một tập tin. Các vấn đề cames tôi đang cố gắng để lưu bitmap vào một tập tin. Đây là mã của tôi:
private void takePic() {
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 2);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 2) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
ImageView test = (ImageView) findViewById(R.id.test);
test.setImageBitmap(photo);
try {
FileOutputStream out = new FileOutputStream("filename");
photo.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Và trường hợp ngoại lệ trong logcat:
04-02 14:46:51.975: W/IInputConnectionWrapper(2225): showStatusIcon on inactive InputConnection
04-02 14:46:56.135: W/System.err(2225): java.io.FileNotFoundException: /filename (Read-only file system)
04-02 14:46:56.135: W/System.err(2225): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
04-02 14:46:56.145: W/System.err(2225): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
04-02 14:46:56.145: W/System.err(2225): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
04-02 14:46:56.145: W/System.err(2225): at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
04-02 14:46:56.145: W/System.err(2225): at java.io.FileOutputStream.<init>(FileOutputStream.java:144)
nó bệ phóng với tôi không có getExternalStorageDirectory() phương pháp – Darko
xem, tôi đã cập nhật mã. –
có nghĩa là bạn không có thẻ SD –