mirror of
https://github.com/dgis/emu48android
synced 2024-11-16 07:48:08 +01:00
This commit is contained in:
parent
a765895abb
commit
a545659a24
1 changed files with 49 additions and 0 deletions
49
app/src/main/java/org/emulator/forty/eight/Utils.java
Normal file
49
app/src/main/java/org/emulator/forty/eight/Utils.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue