android - convert Uri to file path but can not open it in nexus 4 -


i open picture in album , uri. convert uri file path. in log shows mnt/storage/emulated/0/xxx.jpg. covert uri file path way like:

cursor cursor = globalobjectmanager.getinstance().getcontext().getcontentresolver()                     .query(filepathuri, null, null, null, null);  int column_index = cursor.getcolumnindexorthrow(mediastore.images.media.data); filename = cursor.getstring(column_index);  

the problem when open file function catches filenotfoundexception.

string path = "mnt/storage/emulated/0/xxx.jpg"; fileinputstream in = new fileinputstream(path); 

the code works on other devices android 2.3-4.1. far know nexus 4 runs android 4.2 , mnt/storage/emulated/0/ works multi-user.

in app must use fileinputstream() function read byte data of beginning of file.

could tell me how fix bug? thanks!

ok fix it. made big mistake! add mnt/ in front of storage/ needlessly, , takes bug.

i believe seeing /storage/emulated/0. we're seeing problem too, seems related new /storage handling multiple sd cards, think introduced in android 4.1 maybe later. if look, you'll see /storage/emulated/0 not exist on filesystem, not symlink. knows system using path or tricks going on there.

the workaround do:

filename = new file(cursor.getstring(column_index)).getcanonicalpath(); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -