1

I am currently testing the Android SFTP Documents Provider (https://github.com/RikyIsola/Android-SFTP-Documents-Provider). It works fine with the system's Files application (Android 8.1). In particular this file manager show lots of entries in its three-horizontal-bar menu: Downloads, internal, SD, Drive, SFTP and Termux.

In my own application I am using the standard SAF method to open a tree:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        ...
        intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri);
    }
    intent.addFlags(
            Intent.FLAG_GRANT_READ_URI_PERMISSION +
                    Intent.FLAG_GRANT_WRITE_URI_PERMISSION +
                    Intent.FLAG_GRANT_PREFIX_URI_PERMISSION +
                    Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
    startActivityForResult(intent, REQUEST_DIRECTORY_SELECT);
}

Note that the strange "SHOW_ADVANCED" stuff is necessary to see the SD card, for whatever extremely strange reason. However, when the file picker opens, I see only Downloads, Internal and SD. Nothing more.

Worth to mention: The Android Samba Client works fine with my app, i.e. it indeed is visible in the File Picker. But SFTP is not.

Also to mention: The primitive ftpd (also available in F-Droid) also does not show the SFTP DocumentsProvider.

Do I need some manifest-filter-intent-whatever magic? Or is there a fundamental difference between the Samba DocumentsProvider and all others? Is it kind of more powerful?

Rahul Gaur
  • 1,661
  • 1
  • 13
  • 29
  • 1
    Remove all those flags. They are useless. You cannot grant anything. You have to wait until something is granted to you. – blackapps Feb 28 '20 at 21:13
  • `Note that the strange "SHOW_ADVANCED" stuff is necessary to see the SD card, for whatever extremely strange reason. `. The gui is indeed awfull. But you can do without and still find sd card fidling around in de gui. Just have to know how. – blackapps Feb 28 '20 at 21:16
  • If it works in the Files application it should work in your app too. – blackapps Feb 28 '20 at 21:17
  • I do not see your stated app in [the F-Droid catalog](https://search.f-droid.org/?q=sftp&lang=en). However, there is no requirement for a documents provider to support `ACTION_OPEN_DOCUMENT_TREE`. Some just support `ACTION_OPEN_DOCUMENT` and `ACTION_CREATE_DOCUMENT`. – CommonsWare Feb 28 '20 at 21:59
  • Sorry, I mixed things up: The DocumentsProvider for SMB is in F-Droid, but that for SFTP is not. I updated the question accordingly. And I also tried to call ACTION_OPEN_DOCUMENT in my own app, but it just crashed ("no Blabla to handle request"). I could not find a solution for this, some people wrote that it's a system bug on some devices, so I gave up. Maybe the "Files" app works without ACTION_OPEN_DOCUMENT_TREE? But that would be strange. – Andreas K. aus M. Feb 28 '20 at 22:53

2 Answers2

0

The crucial point is the Root.FLAG_SUPPORTS_IS_CHILD flag which is set by SMB Documents Provider, but not by the SFTP Provider. See also [https://stackoverflow.com/a/59390835/5812703]. It's still incomprehensible why the official Android developer documentation does not tell anything about this relation. Finally I had to functionally compare the source code of the two Documents Providers.

PS: The grant flags criticised by blackapps have nothing to do with this concept.

0

For the picker, add

intent.setType("*/*");

Worked for my provider.

halxinate
  • 1,509
  • 15
  • 22