写了个while判断文件是否存在,存在的话改变命名。如下:
class startButtonListener implements OnClickListener { int count = 0 ; @Override public void onClick(View v) { imageFilePath = destDirName + "/pic0.jpg"; File imageFile = new File(imageFilePath); while(imageFile.exists()) { count += 1 ; imageFilePath = destDirName + "/pic" + count + ".jpg" ; imageFile = new File(imageFilePath); } Uri imageFileUri = Uri.fromFile(imageFile); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri); startActivityForResult(i, 1); } }