android 无法将原始文件复制到临时文件

aurhwmvo  于 2022-12-28  发布在  Android
关注(0)|答案(1)|浏览(120)

当我在应用程序中拍摄照片时,应用程序会将纬度和经度信息保存在照片的exif元数据中。
在Galaxy Note 10+中,"exif.saveAttributes()"抛出IOException,但我不知道它是如何出现的。
这是我的准则。

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

我不重命名任何文件,但它失败,因为重命名的临时文件。我该如何解决这个问题?

huwehgph

huwehgph1#

请参阅the answer here。较新版本的Android操作系统会“监管”在DCIM和Pictures等公共文件夹中创建文件。当EXIFInterface尝试创建扩展名为“.tmp”且仅允许“.jpg”、“.png”或“.mp4”的文件时,会失败。

相关问题