Failed to copy original file to temp file

Viewed 634

When I take a photo in my app, my app saved latitude, longitude information in the photo's exif metadata.

In Galaxy Note 10+, "exif.saveAttributes()" throws IOException. But I don't know how it appears.

This is my code.

try {
    double latitude  = data.getDoubleExtra("latitude", 38);
    double longitude = data.getDoubleExtra("longitude", 128);

    String strLatitude  = convertTagGPSFormat(latitude);
    String strLongitude = convertTagGPSFormat(longitude);

    ExifInterface exif = new ExifInterface(imageFilePath);
    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, strLatitude);
    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "N");
    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, strLongitude);
    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "E");
    exif.saveAttributes();
    Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show();
    isCreatedFile = false;
} catch (Exception e) {
    isCreatedFile = false;
    Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT).show();
    e.printStackTrace();
}

2021-02-25 10:13:54.456 7623-7623/com.example.whalemonitorapp W/System.err: java.io.IOException: Failed to copy original file to temp file
2021-02-25 10:13:54.458 7623-7623/com.example.whalemonitorapp W/System.err:     at android.media.ExifInterface.saveAttributes(ExifInterface.java:2098)
2021-02-25 10:13:54.459 7623-7623/com.example.whalemonitorapp W/System.err:     at com.example.whalemonitorapp.MainActivity.onActivityResult(MainActivity.java:439)
2021-02-25 10:13:54.459 7623-7623/com.example.whalemonitorapp W/System.err:     at android.app.Activity.dispatchActivityResult(Activity.java:8310)
2021-02-25 10:13:54.459 7623-7623/com.example.whalemonitorapp W/System.err:     at android.app.ActivityThread.deliverResults(ActivityThread.java:5008)
2021-02-25 10:13:54.459 7623-7623/com.example.whalemonitorapp W/System.err:     at android.app.ActivityThread.handleSendResult(ActivityThread.java:5056)
2021-02-25 10:13:54.460 7623-7623/com.example.whalemonitorapp W/System.err:     at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
2021-02-25 10:13:54.460 7623-7623/com.example.whalemonitorapp W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
2021-02-25 10:13:54.460 7623-7623/com.example.whalemonitorapp W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
2021-02-25 10:13:54.460 7623-7623/com.example.whalemonitorapp W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
2021-02-25 10:13:54.460 7623-7623/com.example.whalemonitorapp W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
2021-02-25 10:13:54.460 7623-7623/com.example.whalemonitorapp W/System.err:     at android.os.Looper.loop(Looper.java:223)
2021-02-25 10:13:54.460 7623-7623/com.example.whalemonitorapp W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7656)
2021-02-25 10:13:54.460 7623-7623/com.example.whalemonitorapp W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2021-02-25 10:13:54.461 7623-7623/com.example.whalemonitorapp W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
2021-02-25 10:13:54.461 7623-7623/com.example.whalemonitorapp W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2021-02-25 10:13:54.463 7623-7623/com.example.whalemonitorapp W/System.err: Caused by: java.io.IOException: Couldn't rename to /storage/emulated/0/Pictures/Whale/WHALE_20210225_101347639105132634869099933.jpg.tmp
2021-02-25 10:13:54.463 7623-7623/com.example.whalemonitorapp W/System.err:     at android.media.ExifInterface.saveAttributes(ExifInterface.java:2084)
2021-02-25 10:13:54.463 7623-7623/com.example.whalemonitorapp W/System.err:     ... 14 more

I don't rename any file, but It fails because of renaming of a temp file. How I can solve this problem?

0 Answers
Related