gpt4 book ai didi

android - 使用用户输入 : Android 创建文件夹

转载 作者:行者123 更新时间:2023-11-29 21:25:22 24 4
gpt4 key购买 nike

jpegCallback = new PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
//int imageNum = 0;

String Name = PatientInfo.getText().toString();

Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory().toString() + Name);
imagesFolder.mkdirs();
Date d = new Date();
CharSequence s = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
File output = new File(imagesFolder, s.toString() + ".jpg");
// String fileName = "image_" + String.valueOf(imageNum) + ".jpg";
// File output = new File(imagesFolder, fileName);
/* while (output.exists()){
imageNum++;
fileName = "image_" + String.valueOf(imageNum) + ".jpg";
output = new File(imagesFolder, fileName);
}*/
Uri uriSavedImage = Uri.fromFile(output);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
OutputStream imageFileOS;

try {
imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
imageFileOS.write(data);
imageFileOS.flush();
imageFileOS.close();

Toast.makeText(AndroidCamera.this,
"Image saved: ",
Toast.LENGTH_LONG).show();

}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{}
Log.d("Log", "onPictureTaken - jpeg");
}
};

这是一个代码示例。我正在尝试在输入时使用用户输入创建文件夹。每次我需要在输入新用户名时创建新文件夹。但是这里缺少一些东西。任何建议都会有所帮助。

最佳答案

改变

File imagesFolder = new File(Environment.getExternalStorageDirectory().toString() + Name);

带文件

File imagesFolder = new File(Environment.getExternalStorageDirectory(),  Name);

请确保在 list 中也有 WRITE_EXTERNAL_PERMISSION,并且 Name 不为空

关于android - 使用用户输入 : Android 创建文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20283930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com