Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android File Chooser Absolute Path Issue

I use the intent filter to get the path of the file selected by the user with a file-chooser, unfortunately I have problem to obtain the absolute path,

the path onActivityResult starts always with various extra data that cause errors in my app

for example

/content/:/myabsolutepath

or

file:///myabsolutepath

and the extra attributes depends on file type, file manager on the phone etc.

I need to get only the absolute path in the form

/myabsolutepath

Here there is my code

private void openFile() {
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.setType("file/*");
        startActivityForResult(i, FILE_REQ_CODE);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent i) {
        //String with the path;
        path = i.getDataString();


        super.onActivityResult(requestCode, resultCode, i);

    }
like image 425
AndreaF Avatar asked Aug 31 '25 20:08

AndreaF


1 Answers

Try:

path = i.getData().getPath();
like image 159
Franco Rapetti Avatar answered Sep 05 '25 05:09

Franco Rapetti