Click here to Skip to main content
14,544,533 members
Rate this:
Please Sign up or sign in to vote.
See more:
//case 1: //Result of Log.i("km",path); /content:/ //what is primary%3ADCIM%2? //Why i'm not getting proper path like documents/document/primary/DCIM/images.jpeg

//case 2:
// DocumentFile d = DocumentFile.fromSingleUri(this, uri);
// Log.i("fe", "path: " + d.getUri().getPath());

//Now getting a colon sign in the path
//what is the problem guys?
//need proper path like /document/primary/DCIM/images.jpeg

What I have tried:

//creating a file chooser
btnSelectFile.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String[] mimeTypes = {"image/*",

                //File Chooser
                Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
                startActivityForResult(Intent.createChooser(intent, "Select a file"), PICK_FILE);


    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (requestCode == PICK_FILE && resultCode == RESULT_OK && data != null) {
            Uri uri = data.getData();

            File fl = new File(uri.toString());
            path = fl.getAbsolutePath();

            Log.i("km", path);
        super.onActivityResult(requestCode, resultCode, data);
Updated 22-May-20 21:47pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The strange characters are the result of HTML encoding to prevent control characters being misinterpreted. For example, in the string

the %3A is a colon (:), and the %2F is a forward solidus (/).

See HTML URL Encoding Reference[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100