1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
public
static
String getRealFilePath(
final
Context context,
final
Uri uri ) {
if
(
null
== uri )
return
null
;
final
String scheme = uri.getScheme();
String data =
null
;
if
( scheme ==
null
)
data = uri.getPath();
else
if
( ContentResolver.SCHEME_FILE.equals( scheme ) ) {
data = uri.getPath();
}
else
if
( ContentResolver.SCHEME_CONTENT.equals( scheme ) ) {
Cursor cursor = context.getContentResolver().query( uri,
new
String[] { ImageColumns.DATA },
null
,
null
,
null
);
if
(
null
!= cursor ) {
if
( cursor.moveToFirst() ) {
int
index = cursor.getColumnIndex( ImageColumns.DATA );
if
( index > -
1
) {
data = cursor.getString( index );
}
}
cursor.close();
}
}
return
data;
}
|