我想将已捕获的image
从camera
保存到extSdcard
,但问题images
存储在internal memory
的手机android 4.4.4(kitkat)
中android 5.1.1
1}}和android 4.2
,但extsdcard
图片已存储在__set()
中,请您对此有何疑问?
答案 0 :(得分:0)
根据Document
不得允许应用程序写入辅助外部存储 设备,特定于包装
您可以写在primary external storage
上的应用专用文件夹,即/sdcard/Android/data/package/
和secondary external storage
上的应用专用文件夹,即/extSdcard/Android/data/package/
和WRITE_EXTERNAL_STORAGE
即可写入primary external storage
上的所有位置,即/sdcard/
,但您无法写入secondary
external storage
上的任何位置(应用特定文件夹除外)。
答案 1 :(得分:0)
所以我必须创建一个文件夹,其中包含我的应用程序包的名称,但在我的应用程序的代码中,我必须进行更改?这是我的代码
Button captureButton = (Button) findViewById(R.id.button_capture);
captureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCamera.takePicture(null, null, mPicture);
}
/**
* Helper method to access the camera returns null if it cannot get the
* camera or does not exist
*
* @return
*/
private Camera getCameraInstance() {
Camera camera = null;
try {
camera = Camera.open();
} catch (Exception e) {
// cannot get camera or does not exist
}
return camera;
}
PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {
return;
}
try {
pictureFile.createNewFile();
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
};
private static File getOutputMediaFile() {
File mediaStorageDir = new File(Environment.getExternalStorageDirectory() + "/MyCameraApp/");
if (!mediaStorageDir.exists()) {
mediaStorageDir.mkdir();
}
return mediaStorageDir;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
return true;
}
private String currentDateFormat(){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HH_mm_ss");
String currentTimeStamp = dateFormat.format(new Date());
return currentTimeStamp;
}
}