add some string

This commit is contained in:
dxl
2020-08-13 17:55:54 +08:00
parent 033fc34aff
commit e6607cad6c
7 changed files with 62 additions and 42 deletions
@@ -354,43 +354,52 @@ public class FileUtils {
private static String getFilePathByUri_BELOWAPI11(Uri uri) {
// 以 content:// 开头的,比如 content://media/extenral/images/media/17766
if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
String path = null;
String[] projection = new String[]{MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
try {
if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
String path = null;
String[] projection = new String[]{MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if (columnIndex > -1) {
path = cursor.getString(columnIndex);
}
} catch (Exception e) {
e.printStackTrace();
}
}
cursor.close();
}
return path;
}
} catch (Exception e) {
return null;
}
return null;
}
private static String getFilePathByUri_API11to18(Uri contentUri) {
String result = null;
try {
String[] projection = {MediaStore.Images.Media.DATA};
CursorLoader cursorLoader = new CursorLoader(context, contentUri, projection, null, null, null);
Cursor cursor = cursorLoader.loadInBackground();
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if (columnIndex > -1) {
path = cursor.getString(columnIndex);
}
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
result = cursor.getString(column_index);
} catch (Exception e) {
e.printStackTrace();
}
}
cursor.close();
}
return path;
}
return null;
}
private static String getFilePathByUri_API11to18(Uri contentUri) {
String[] projection = {MediaStore.Images.Media.DATA};
String result = null;
CursorLoader cursorLoader = new CursorLoader(context, contentUri, projection, null, null, null);
Cursor cursor = cursorLoader.loadInBackground();
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
result = cursor.getString(column_index);
} catch (Exception e) {
e.printStackTrace();
}
}
cursor.close();
} catch (Exception e) {
return null;
}
return result;
}