Updates file name handling method on Android (#487)
This commit is contained in:
parent
f498c22e6c
commit
692d7980f2
|
@ -1,5 +1,6 @@
|
||||||
## 2.1.2
|
## 2.1.3
|
||||||
Fixed desktop plugin implementation
|
Android: Updates file name handling method. ([#487](https://github.com/miguelpruivo/flutter_file_picker/issues/487)).
|
||||||
|
Desktop (Go): Fixed desktop plugin implementation (thank you @DenchikBY).
|
||||||
|
|
||||||
## 2.1.1
|
## 2.1.1
|
||||||
iOS: Fixes an issue that could result in a crash when selecting a media item twice. ([#518](https://github.com/miguelpruivo/flutter_file_picker/issues/518)).
|
iOS: Fixes an issue that could result in a crash when selecting a media item twice. ([#518](https://github.com/miguelpruivo/flutter_file_picker/issues/518)).
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
import android.provider.DocumentsContract;
|
import android.provider.DocumentsContract;
|
||||||
|
import android.provider.OpenableColumns;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
|
@ -55,36 +56,30 @@ public class FileUtils {
|
||||||
public static String getFileName(Uri uri, final Context context) {
|
public static String getFileName(Uri uri, final Context context) {
|
||||||
String result = null;
|
String result = null;
|
||||||
|
|
||||||
//if uri is content
|
try {
|
||||||
if (uri.getScheme() != null && uri.getScheme().equals("content")) {
|
|
||||||
Cursor cursor = null;
|
if (uri.getScheme().equals("content")) {
|
||||||
try {
|
Cursor cursor = context.getContentResolver().query(uri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null);
|
||||||
cursor = context.getContentResolver().query(uri, null, null, null, null);
|
try {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
//local filesystem
|
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
||||||
int index = cursor.getColumnIndex("_data");
|
|
||||||
if (index == -1)
|
|
||||||
//google drive
|
|
||||||
{
|
|
||||||
index = cursor.getColumnIndex("_display_name");
|
|
||||||
}
|
}
|
||||||
result = cursor.getString(index);
|
} finally {
|
||||||
if (result != null) {
|
|
||||||
uri = Uri.parse(result);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (final Exception ex) {
|
|
||||||
Log.e(TAG, "Failed to decode file name: " + ex.toString());
|
|
||||||
} finally {
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (result == null) {
|
||||||
|
result = uri.getPath();
|
||||||
|
int cut = result.lastIndexOf('/');
|
||||||
|
if (cut != -1) {
|
||||||
|
result = result.substring(cut + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex){
|
||||||
|
Log.e(TAG, "Failed to handle file name: " + ex.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return uri.toString();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean clearCache(final Context context) {
|
public static boolean clearCache(final Context context) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0915ff87e81a3bfb122df4ced418a2b0
|
32b17685cd2c55cd4f786d731516419d
|
|
@ -16,7 +16,7 @@ class PlatformFile {
|
||||||
this.bytes = data['bytes'],
|
this.bytes = data['bytes'],
|
||||||
this.size = data['size'];
|
this.size = data['size'];
|
||||||
|
|
||||||
/// The absolute path for a cached copy of this file. It can be used to create a
|
/// The absolute path for a cached copy of this file. It can be used to create a
|
||||||
/// file instance with a descriptor for the given path.
|
/// file instance with a descriptor for the given path.
|
||||||
/// ```
|
/// ```
|
||||||
/// final File myFile = File(platformFile.path);
|
/// final File myFile = File(platformFile.path);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
name: file_picker
|
name: file_picker
|
||||||
description: A package that allows you to use a native file explorer to pick single or multiple absolute file paths, with extension filtering support.
|
description: A package that allows you to use a native file explorer to pick single or multiple absolute file paths, with extension filtering support.
|
||||||
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
|
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
|
||||||
version: 2.1.2
|
version: 2.1.3
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
|
Loading…
Reference in New Issue