|
|
@@ -1,13 +1,14 @@
|
|
|
package com.datarecovery.master.utils;
|
|
|
|
|
|
import android.content.Context;
|
|
|
-import android.database.Cursor;
|
|
|
import android.net.Uri;
|
|
|
-import android.provider.MediaStore;
|
|
|
import android.text.format.Formatter;
|
|
|
|
|
|
+import androidx.documentfile.provider.DocumentFile;
|
|
|
+
|
|
|
import com.atmob.common.runtime.ContextUtil;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.Locale;
|
|
|
|
|
|
public class FileUtil {
|
|
|
@@ -32,18 +33,18 @@ public class FileUtil {
|
|
|
return split[split.length - 1].toUpperCase(Locale.getDefault());
|
|
|
}
|
|
|
|
|
|
- public static long getFileCreationDate(Context context, Uri uri) {
|
|
|
- String[] projection = new String[]{MediaStore.Images.ImageColumns.DATE_ADDED}; // 根据不同类型的文件选择合适的列名
|
|
|
-
|
|
|
- try (Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null)) {
|
|
|
-
|
|
|
- if (cursor != null && cursor.moveToFirst()) {
|
|
|
- int dateAddedColumnIndex = cursor.getColumnIndexOrThrow(projection[0]);
|
|
|
-
|
|
|
- return cursor.getLong(dateAddedColumnIndex);
|
|
|
+ public static long getFileCreationDateFromUri(Context context, Uri uri, String path) {
|
|
|
+ DocumentFile documentFile = DocumentFile.fromSingleUri(context, uri);
|
|
|
+ if (documentFile != null && documentFile.exists()) {
|
|
|
+ return documentFile.lastModified();
|
|
|
+ } else {
|
|
|
+ if (path != null) {
|
|
|
+ File file = new File(path);
|
|
|
+ return file.lastModified();
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
}
|
|
|
}
|
|
|
- return 0;
|
|
|
}
|
|
|
|
|
|
|