So now I'm writing custom camera, and I want to write location into images that I captured, for some reason I cannot use builder.set() here. The file was created like this:
String name = System.currentTimeMillis() + ".jpg";
file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM + "/Camera"), name);
To make question simple, I just simply create an ExifInterface with a correct file path, and call saveAttributes() method,it looks like this:
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
exif.saveAttributes();
but then I get this log,
D/qdgralloc: GetYUVPlaneInfo: Invalid format passed: 0x21
D/MediaScannerConnection: Scanned /storage/emulated/0/DCIM/Camera/1619507958498.jpg to content://media/external_primary/images/media/11032
V/haha: Failed to copy original file to temp file
W/System.err: java.io.IOException: Failed to copy original file to temp file
at android.media.ExifInterface.saveAttributes(ExifInterface.java:2098)
at com.example.secondpractice.fragment.CameraFragment.takeDelayedPicture(CameraFragment.java:1042)
at com.example.secondpractice.fragment.CameraFragment.onClick(CameraFragment.java:1301)
at com.example.secondpractice.fragment.-$$Lambda$zncvcj43pAXOQyaoJTDWHHAg_tA.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:7496)
at android.view.View.performClickInternal(View.java:7473)
at android.view.View.access$3600(View.java:831)
W/System.err: at android.view.View$PerformClick.run(View.java:28647)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7876)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
W/System.err: Caused by: java.io.IOException: Couldn't rename to /storage/emulated/0/DCIM/Camera/1619507958498.jpg.tmp
at android.media.ExifInterface.saveAttributes(ExifInterface.java:2084)
... 14 more
I think problem happens here:Caused by: java.io.IOException: Couldn't rename to /storage/emulated/0/DCIM/Camera/1619507958498.jpg.tmp
By the way, the getAttributes() works fine, only saveAttributes() has the problem
please help me to check how to solve this. Thanks a lot
On an Android 11 device the OS is very picky concerning extensions.
You can create .jpg, .png and .webp files in DCIM directory and maybe other image files.
But not .tmp files as they are no image files.
So you are victim of the ExifInterface programmers.
If they had decided for .jpg.jpg and not for .jpg.tmp you would not have this trouble.
File an issue/report.