Issues traversing through directory hierarchy with Android Storage Access Framework / DocumentProvider using MTP

前端 未结 3 417
名媛妹妹
名媛妹妹 2020-12-11 20:47

UPDATE: My initial question may be misleading so I want to rephrase it: I want to traverse through the hierarchy tree from an MTP connected device through Android\'s Storage

相关标签:
3条回答
  • 2020-12-11 21:04

    The flags added before start activity for result do nothing.

    I do not understand that you use DocumentsContract. The user picks a directory. From the uri you get you can construct a DocumentFile for that directory.

    After that use DocumentFile::listFiles() on that instance to get a list of subdirectories and files.

    0 讨论(0)
  • 2020-12-11 21:18

    I am using your code to go in sub folders with adding lines:

    Uri childrenUri;
    try {
        //for childs and sub child dirs
        childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(uri, DocumentsContract.getDocumentId(uri));
    } catch (Exception e) {
        // for parent dir
        childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(uri, DocumentsContract.getTreeDocumentId(uri));
    }
    
    0 讨论(0)
  • 2020-12-11 21:26

    After different attempts, I'm not sure there is a way around this SecurityException for an MTP Data Source (unless someone can refute me on this). Looking at the DocumentProvider.java source code and the stack trace, it appears that the call to DocumentProvider#isChildDocument inside DocumentProvider#enforceTree may not have been properly overriden in the MtpDocumentProvider implementation in the Android framework. Default implementation always returns false. #sadface

    0 讨论(0)
提交回复
热议问题