android - Getting file path from uri on emulator -


i want file path uri video. following method works fine when testing real device, however, fails (returns null) when testing on emulator.

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

what correct way of getting file path uri on emulator?

the following method works fine when testing real device

only on the device tried, , app tried. particularly on android 4.4+, approach unreliable. because a uri not file. on older versions of android, uri mediastore, approach might work.

nowadays, not attempt file uri. consume uri supposed to, using methods on contentresolver inputstream, mime type, etc.

what correct way of getting file path uri on emulator?

there none. there not have file path associated uri, let alone path app able access using java file i/o.


Popular posts from this blog