See the following for more information:

Since Calibre Documents Provider is built as a standard Android documents provider, third party applications can access its capabilities using standard Android content provider and documents provider APIs. In this way, any application, when properly integrated, can browse book files through a calibre Content Server, including OPF and cover images, in addition to base book files themselves.

Following is a sample Kotlin code snippet demonstrating how to browse and access book files:

    private val mBookUri: Uri? = null
    private val mSelectDoc = registerForActivityResult(
        ActivityResultContracts.StartActivityForResult()
    ) { result: ActivityResult -> handleSelectDocResult(result.resultCode, result.data) }

    // Launch system document picker to allow user to grant access to document
    private fun launchDocumentPicker() {
        mSelectDoc.launch(Intent(Intent.ACTION_OPEN_DOCUMENT))
    }

    // Persist granted read permission for document
    private fun handleSelectDocResult(resultCode: Int, data: Intent?) {
        if (resultCode == Activity.RESULT_OK && data != null) {
            contentResolver.takePersistableUriPermission(
                data.data!!, Intent.FLAG_GRANT_READ_URI_PERMISSION
            )
        }
    }

    // Open book file input stream
    private fun openBook(): InputStream? {
        var fileStream: InputStream? = null

        try {
            fileStream = contentResolver.openInputStream(mBookUri!!)
        } catch (exception: Throwable) {
            // Handle error
        }

        return fileStream
    }
			

Edit Book Information

The standard Android content provider and documents provider interfaces that Calibre Documents Provider implements allows integrating applications to achieve read access to book files. To achieve update access however, integrating applications like eLibrary Manager must make use of a custom API that is invoked through the ContentProvider.call() method.

To update book information in a calibre library, integrating applications call method kpw.ebook.calibre.setFields through the Calibre Documents Provider call() interface. The arguments for the method are

You can see sample code demonstrating such a call below.

The list of book info or metadata that can be updated using this mechanism includes

Following is a sample Kotlin code snippet demonstrating use of the book info update API:

    private fun updateBookInfo() {
        val bookUri = Uri.Builder()
            .scheme("content")
            .authority("kpw.ebook.calibre.documents")
            .path("document")
            .appendPath("calibre_library:books/The Aeneid (1308)/The Aeneid.epub")
            .build()

        val updatedBookInfo = Bundle()
        updatedBookInfo.putStringArray("tags", arrayOf("Classics", "Verse", "Fiction"))
        updatedBookInfo.putInt("rating", 8)
        updatedBookInfo.putString(
            "comments", "<div><p><i>The Aeneid</i> is a Latin poem "
                    + "written by Virgil in the 1st century BC (between 29 and 19 BC) that "
                    + "tells the legendary story of Aeneas, a Trojan who travelled to Italy, "
                    + "where he became the ancestor of the Romans.</p></div>"
        )
        updatedBookInfo.putString("series", null)

        val results = contentResolver.call(
            "content://kpw.ebook.calibre.documents/call".toUri(),
            "kpw.ebook.calibre.setFields",
            bookUri.toString(),
            updatedBookInfo
        )

        Log.d("kpw", "submitted=${results?.getBoolean("updatesSubmitted")}")
    }