This commit is contained in:
dgis 2019-02-03 23:09:25 +00:00
parent a765895abb
commit a545659a24

View file

@ -0,0 +1,49 @@
package org.emulator.forty.eight;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.OpenableColumns;
public class Utils {
public static String getFileName(Context context, String url) {
Uri uri = Uri.parse(url);
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
public static String getFilePath(Context context, String url) {
Uri uri = Uri.parse(url);
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(0);
}
} finally {
cursor.close();
}
}
if (result == null)
result = url;
return result;
}
}