Я новичок в разработке приложений. Я хочу разработать приложения, которые могут сохранять несколько изображений в SD-карте. После нескольких исследований, на YouTube или на этой странице ни один из них не может помочь мне или, может быть, я не могу их понять. Например, android take multiple image with camera. На этой странице показано, как сохранять изображения на сервере базы данных, но мне они нужны на SD-карте. Моя проблема с моим кодом заключается в том, что новое изображение будет заменено более старым. Вот мой код.Добавить несколько изображений в sdcard
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;
}
Надеюсь, я улучшусь.
I see.So, u использует метод getTime() для изменения каждого имени файла. Я никогда не знал, что метод существует. Мне нужно узнать больше. Благодаря! за помощь. – Zaidi