我有这个代码从我的应用程序拍照,然后保存到默认的不同目录:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
directory_path = "/tempCamera";
directory = new File(Environment.getExternalStorageDirectory(),
directory_path);
if (!directory.exists()) {
directory.mkdirs();
}
camera_button = (Button) findViewById(R.id.camera_button);
camera_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent camera_intent = new Intent(
MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(directory));
MainActivity.this.startActivityForResult(camera_intent, 0);
}
});
}
但图片始终保存在默认目录中。怎么了?
答案 0 :(得分:3)
您应该传递给MediaStore.EXTRA_OUTPUT,而不是文件夹的路径,而是传递给结果图像的路径。