Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在时间戳时间段已过后附加带有时间戳的图片_Java_Android_Android Studio_Android Intent - Fatal编程技术网

Java 在时间戳时间段已过后附加带有时间戳的图片

Java 在时间戳时间段已过后附加带有时间戳的图片,java,android,android-studio,android-intent,Java,Android,Android Studio,Android Intent,我正在为一家当地公司开发一款保险应用程序,我已经掌握了捕获带有时间戳的事故照片并将其保存到目录中的基本知识 Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); String timeStamp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date()); File imagesFolder = new Fil

我正在为一家当地公司开发一款保险应用程序,我已经掌握了捕获带有时间戳的事故照片并将其保存到目录中的基本知识

Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String timeStamp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date());

File imagesFolder = new File(Environment.getExternalStorageDirectory(), "DCIM/Camera");

File image = new File(imagesFolder, "ACCIDENT_PHOTO_" + timeStamp + ".jpg");

Uri uriSavedImage = Uri.fromFile(image);

private void PictureApp() {
    imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
    startActivityForResult(imageIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
现在我想附加并发送这张图片,但是如果实际的时间戳时间段已经过了,我如何将“时间戳”实现到Uri.from.File中呢

以下是我目前发送事故照片的意图:

private void SharePicApp() {
        final Intent ei = new Intent(Intent.ACTION_SEND_MULTIPLE);
        ei.setType("image/jpeg");
        ei.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@gmail.com"});
        ei.putExtra(Intent.EXTRA_SUBJECT, "LMR Accident Photos");

        ArrayList<Uri> uris = new ArrayList<>();
        uris.add(Uri.fromFile(new File(imagesFolder, "ACCIDENT_PHOTO_" + timeStamp + ".jpg")));

        ei.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        startActivityForResult(Intent.createChooser(ei, "Sending Accident Photos"), 12345);
}
private void SharePicApp(){
最终意图ei=新意图(意图、行动、发送、多次);
ei.setType(“图像/jpeg”);
ei.putExtra(Intent.EXTRA_电子邮件,新字符串[]{”email@gmail.com"});
ei.putExtra(Intent.EXTRA_主题,“LMR事故照片”);
ArrayList URI=新的ArrayList();
add(Uri.fromFile(新文件(imagesFolder,“事故照片”+时间戳+”.jpg));
ei.putParcelableArrayListExtra(Intent.EXTRA_流,URI);
startActivityForResult(Intent.createChooser(ei,“发送事故照片”),12345;
}

“时间戳时间段过后”您能详细说明一下您的意思吗?就像我在上午10:35拍摄照片并尝试在上午10:36附加照片一样,“时间戳”已经过了,附加意图无法找到照片,因为时间戳=时间段=10:35已经过了。希望这能解释更多。非常感谢您的意见。如果您在发送邮件时根据当前时间查找附件,我认为您的设计存在很大缺陷。所以我的建议是:重新审视你的设计,思考如何以更优雅的方式解决这个问题……谢谢Ben。是的,我正在考虑在时间戳的末尾添加一个增量1_2_3,但我不确定如何实现命名图片的增量代码:File image=new File(imagesFolder,“chance_PHOTO”+timestamp+“_1”+”.jpg”);