0
我是應用程序開發中的新手。我想開發一個可以在SD卡中保存多個圖像的應用程序。在我做了多項研究之後,在YouTube或此頁面上,他們都無法幫助我,或者我無法理解它們。例如,android take multiple image with camera。 這個頁面只是顯示如何將圖像保存在數據庫服務器中,但我需要它們在SD卡上。我的代碼問題是,捕獲的新圖像將替換舊圖像。這是我的代碼。在SD卡中添加多個圖片
Button button;
ImageView imageView;
static final int CAM_REQUEST = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.capimg);
button = (Button) findViewById(R.id.button);
imageView = (ImageView) findViewById(R.id.image_view);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent camera_intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = getFile();
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(camera_intent, CAM_REQUEST);
}
});
}
private File getFile() {
File folder = new File("sdcard/UTP_app");
if (!folder.exists()) {
folder.mkdir();
}
File image_file = new File(folder, "cam_image.jpg");
if (image_file.exists()) {
return image_file;
}
File image_file2 = new File(folder, "cam_image2.jpg");
if (image_file2.exists()) {
return image_file2;
}
File image_file3 = new File(folder, "cam_image3.jpg");
if (image_file3.exists()) {
return image_file3;
}
return folder;
}
我希望我會改善。
我明白了。所以,您正在使用getTime()方法更改每個文件名。我從來不知道這種方法存在。我需要學習更多。謝謝!幫助我。 – Zaidi