Privatestring Getrealpath (Uri fileUrl) {string FileName=NULL; Uri Filepathuri=FileUrl; if(FileUrl! =NULL ) { if(Fileurl.getscheme (). toString (). CompareTo ("content") = = 0)//content://URI starting with{cursor cursor= This. Getcontentresolver (). Query (FILEURL,NULL,NULL,NULL,NULL ); if(Cursor! =NULL&&Cursor.movetofirst ()) { intColumn_index =Cursor.getcolumnindexorthrow (MediaStore.Images.Media.DATA); FileName= Cursor.getstring (Column_index);//Remove file path if(!filename.startswith ("/mnt" ) ) { //Check if there is a "/mnt" prefixFileName= "/mnt" +FileName; } cursor.close (); } } Else if(Fileurl.getscheme (). CompareTo ("file") = = 0)//File:///start of Uri{fileName=filepathuri.tostring (); FileName= Filepathuri.tostring (). Replace ("file://", "" " ); //Replace file:// if(!filename.startswith ("/mnt" ) ) { //Plus "/mnt" head .FileName + = "/mnt"; } } } returnFileName; }
Ways to get the correct file path for the URI for Android