Can an Android plugin access files using joplin.plugins.dataDir?

Hello, I would like to ask if there is a way to read/write files on Android devices inside the folder returned from joplin.plugins.dataDir()?

Yes that's the purpose of this directory, a place for your plugin to store its own files

Thanks, but how? Any API for file read/write/delete? Can I use joplin.require(‘fs-extra’)? Or do I need to use some other library?

If fs-extra works you can use that

Nope, just tried, doesn’t work. joplin.require('fs-extra') returns an empty object on Android.

Hmm, yes that would make sense since this package is most likely not available on mobile. @personalizedrefriger may be able to confirm since he implemented the mobile plugin support.

In general, file access is unsupported for mobile plugins.

Related prior work:

  • (Unmerged/Android and web only) Creating a custom WebView implementation on Android to allow plugins to access load local files as WASM, etc. The custom WebView implementation was originally created when attempting to allow custom voice typing plugins to be created. While needed for microphone access and possibly WASM loading, I don't think it was necessary for the "load local files" part of the change.

    Side-note: Why a custom WebView
    • Joplin currently uses react-native-webview for the plugin runner, note viewer, and note editor. This library doesn't seem to support loading local content without using file:// URLs or hosting a local webserver. Joplin currently uses file:// URLs.
    • The change linked above hosts the plugin runner WebView with a WebViewAssetLoader. This allows access to certain features that are currently unavailable to the plugin runner/note viewer because it is hosted from a file:// URL. For example, this allowed voice typing plugins to access the microphone access for the voice typing feature.
      • Using a file:// URL for local content and is marked as an antipattern in the relevant Android documentation. As such, the WebViewAssetLoader-based WebView may also provide greater control over content/security compared to file:// URLs.
    • If I recall correctly, the custom WebView implementation also allowed for faster file transfer (using fetch or just URLs directly) between the WebView and the main process.
1 Like

@KithLo , what kind of file do you need to store, and what's your use case? Maybe you can just store as private setting if it's not too large

Thanks for the help. Is there a size limit for private settings? If I put something like 10MB of data would it be fine?

It would help to know what you're trying to do. 10MB seems like a lot but it might work