0

I want to pick a file from mysdcard (and then I upload to a server). I try to use Intent.ACTION_OPEN_DOCUMENT_TREE to select the file using this post:

How to use the new SD card access API presented for Android 5.0 (Lollipop)?

but when I try to select the file, this is the message I receive from Android studio:

1489-1563/system_process W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client

I've searched on the web, and it seems like no OnclickListener on the item I clicked (?).

This is the code I use to pick the file:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
            startActivityForResult(intent, 42);

And how I handle the response:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Uri treeUri = data.getData();
        DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);

        // List all existing files inside picked directory
        for (DocumentFile file : pickedDir.listFiles()) {
            Log.d("PATH FILE", "Found file " + file.getName() + " with size " + file.length());
        }
    }
}

Where is my error? Sorry but I'm newly in android!

Community
  • 1
  • 1
mary
  • 83
  • 2
  • 8
  • "this is the message I receive from Android studio" -- that warning message does not seem to have anything to do with your code. "it seems like no OnclickListener on the item I clicked" -- you are asking to open a document tree; you will only be able to click on folders, not files. – CommonsWare Jul 03 '16 at 16:09
  • You're right, I'm sorry, I'm very newly in android. I've resolved using this http://stackoverflow.com/questions/8885204/how-to-get-the-file-path-from-uri to select the file and obtain the path and this http://stackoverflow.com/questions/3401579/get-filename-and-path-from-uri-from-mediastore to convert the result in absolute path. Thanks – mary Jul 12 '16 at 14:28

0 Answers0