java - Android Intent ACTION_GET_CONTENT does not return extension of file -


i trying path of file selected user, using calling intent action_get_content result.

the problem when selecting audio file file manager, intent not return extension of file (which there in file name checked it). in case of video or image working fine.

here code:

intent calling:

intent intent = getintent(); if(intent.getaction() == null) {     if(build.version.sdk_int >= build.version_codes.kitkat)         intent = new intent(intent.action_open_document);     else         intent = new intent(intent.action_get_content);     intent.settype("*/*");     intent.addcategory(intent.category_openable);     startactivityforresult(intent.createchooser(intent, "select file upload"),cloudconstants.cloud_request_file_chooser); 

on result code:

    if (data != null) {     //get uri data intent - uri of file chosen user in     //file picker     urifileuri = data.getdata();     if(urifileuri != null && build.version.sdk_int >= build.version_codes.kitkat) {     final int intflags = data.getflags()&(intent.flag_grant_read_uri_permission|intent.flag_grant_write_uri_permission); getcontentresolver().takepersistableuripermission(data.getdata(), intflags); }     //check if uri returned or not; null returned if file chosen     //via gallery share option     //in such case, uri retrieved clipdata object of intent     if (urifileuri == null && build.version.sdk_int >= build.version_codes.jelly_bean && data.getclipdata().getitemcount() > 0)         urifileuri = data.getclipdata().getitemat(0).geturi();     //log file uri     log.i("cloudmedia", "file uri: " + string.valueof(urifileuri));     //generate absolute file name publish on title     strfilename = getfileinformation(urifileuri, mediastore.files.filecolumns.display_name); 

getfileinformation function:

public string getfileinformation(uri strfileuri, string strprojection) {         cursor cursorfileid = getcontentresolver().query(strfileuri,                 new string[] {                         strprojection                 }, null, null, null);         if(cursorfileid.movetofirst()) {             return cursorfileid.getstring(cursorfileid.getcolumnindex(strprojection));         } else             return null;     } 

so strfilename not contain extension of audio file selected. want audio file extension also.

            uri selectedimage = data.getdata();             string[] filepathcolumn = { mediastore.images.media.data };             cursor cursor = getcontentresolver().query(selectedimage, filepathcolumn, null, null, null);             cursor.movetofirst();             int columnindex = cursor.getcolumnindex(filepathcolumn[0]);             string imgfullpath = cursor.getstring(columnindex);             cursor.close();//string file = uri.tostring(); 

source http://programmerguru.com/android-tutorial/how-to-pick-image-from-gallery/


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -