Android 更改相机单击的照片路径
我正在开发一个点击照片的应用程序,它应该将照片存储在不同于默认存储位置的文件夹中。请告诉我这件事Android 更改相机单击的照片路径,android,Android,我正在开发一个点击照片的应用程序,它应该将照片存储在不同于默认存储位置的文件夹中。请告诉我这件事 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // create Intent to take a picture and return control to the calling appl
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
这是基本代码,请告诉我需要在其中进行的更改。您不能更改默认文件夹位置,但可以复制图像供您使用。如果要更改,请使用系统摄像头进行播放。 您需要调用“活动结果”,获取捕获的图像并将其存储在任何位置。 对于我的案例文件(图像),名称为currenttimestamp.jpg 编辑 告诉安卓你已经复制了图片。这将使文件夹在用户设备上显示为库,只需将路径和mimetype传递到媒体扫描程序连接
conn.scanFile(fos..getAbsolutePath(),"image/*");
**结束编辑*
fis.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static MediaScannerConnection conn;
*编辑设置mediascanner连接*
fis.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static MediaScannerConnection conn;
onCreate()中的某个地方
Intent-imageIntent=newintent(android.provider.MediaStore.ACTION\u-IMAGE\u-CAPTURE);
File imagesFolder=新文件(Environment.getExternalStorageDirectory(),“MyProjectName”);
如果(!imagesFolder.exists()){
imagesFolder.mkdirs()//
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyProjectName");
if (!imagesFolder.exists()) {
imagesFolder.mkdirs();// <----Do Not Forget this
}
SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy_HHmmss_Z");
String currentDateandTime = sdf.format(new Date());
String fileName = "image_" + String.valueOf(currentDateandTime) + ".jpg";
File output = new File(imagesFolder, fileName);
Uri uriSavedImage = Uri.fromFile(image);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
imageFileOS.write(arg0);
imageFileOS.flush();
imageFileOS.close();
Toast.makeText(AndroidCamera.this,
"Image saved: ",
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);