Sometimes the path will be obtained from other file browsers. When the path is used to retrieve files from the database, it will be unsuccessful because there are too many file browsers in Android and the paths returned are inconsistent, the path in the android database is an absolute path, that is, the path starting with "/mnt.
Private string getrealpath (URI fileurl ){
String filename = NULL;
Uri filepathuri = fileurl;
If (fileurl! = NULL ){
If (fileurl. getscheme (). tostring (). compareto ("content") = 0) // content: // URI starting
{
Cursor cursor = mcontext. getcontentresolver (). Query (videourl, null );
If (cursor! = NULL & cursor. movetofirst ())
{
Int column_index = cursor. getcolumnindexorthrow (***. data );
Filename = cursor. getstring (column_index); // retrieves the file path
If (! Filename. startswith ("/mnt ")){
// Check whether the prefix "/mnt" exists
Filename = "/mnt" + filename;
}
Cursor. Close ();
}
} Else if (videourl. getscheme (). compareto ("file") = 0) // URI starting with file: //
{
Filename = filepathuri. tostring ();
Filename = filepathuri. tostring (). Replace ("file ://","");
// Replace file ://
If (! Filename. startswith ("/mnt ")){
// Add the "/mnt" Header
Filename + = "/mnt ";
}
}
}
Return filename;
}