android - cant get file path from URI -


i trying open intent lets me choose file. im able select file when try creating file uri got in onactivityresult method file size of 0. dont think im getting right file path.

  file file = new file(environment.getexternalstoragedirectory().getpath()+"/testapp4");         intent intent = new intent();         intent.setaction(intent.action_get_content);         uri data = uri.fromfile(file);         string type = "*/*";         intent.setdataandtype(data, type);         startactivityforresult(intent, 12); 

onactivityresult:

         uri u= data.getdata();          file file = new file( u.getpath);          file.length() // give 0 

public string getrealpathfromuri(context context, uri contenturi) {   cursor cursor = null;   try {      string[] proj = { mediastore.images.media.data };     cursor = context.getcontentresolver().query(contenturi,  proj, null, null, null);     int column_index = cursor.getcolumnindexorthrow(mediastore.images.media.data);     cursor.movetofirst();     return cursor.getstring(column_index);   } {     if (cursor != null) {       cursor.close();     }   } } 

get filename , path uri mediastore


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -