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:/com.android.externalstorage.documents/document/primary%3ADCIM%2Fimages.jpeg //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());

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


What I have tried:

//creating a file chooser
btnSelectFile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String[] mimeTypes = {"image/*",
                        "application/pdf",
                        "application/zip",
                        "application/vnd.ms-powerpoint",
                        "application/vnd.openxmlformats-officedocument.presentationml.presentation",
                        "application/msword",
                        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                        "text/plain"
                };

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

            }
        });

//OnActivityResult
@Override
    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);
    }
Posted
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
/com.android.externalstorage.documents/document/primary%3ADCIM%2Fimages.jpeg


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