我是android编程的初学者。 这是一个代码,用于拍摄图像并将其保存在SD卡的文件夹中。图像保存在图库中,但不会保存在我想要的位置。请帮忙......
public class CameraActivity extends Activity {
/** Called when the activity is first created. */
Button button1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1=(Button)findViewById(R.id.button1);
}
public void send(View v)
{
Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(
Environment.getExternalStorageDirectory(),
"MyImages");
imagesFolder.mkdirs(); //
File image = new File(imagesFolder, "image_001.jpg");
Uri uriSavedImage = Uri.fromFile(image);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(imageIntent,0);
}
}
答案 0 :(得分:2)
最后我得到了解决方案,修改后的代码是:
File image = new File("/sdcard/picture.jpg");
Uri uriSavedImage = Uri.fromFile(image);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
答案 1 :(得分:0)
您应该将/
附加到MyImages字符串。例如,
new File(Environment.getExternalStorageDirectory() + "/MyImages/");
这应该创建对目录的引用,而不是当前的文件。