(Regards this API api/src/main/java/com/ichi2/anki/api/AddContentApi.kt and Third Party Apps · ankidroid/Anki-Android Wiki · GitHub )
Right now, editing existing notes through the AnkiDroid API isn’t very practical. You can update notes if you have their noteId
, but that means third-party apps have to keep track of all those IDs themselves - which is pretty inconvenient and easy to mess up.
It’d be a lot easier if the API let you search for notes based on field content (like the front of the card) to get the noteId
when needed. Also, some way to delete notes through the API would be also good, but I guess this would be a bit sensitive.
3 Likes
I ran into the same issue (deleting) and wanted to find some answers before coding it myself, so I found your post… then coded it myself
Deleting is definitely supported, and I suspect the search too.
You have to implement it yourself, and sadly… you can’t use the existing class.
You can wrap it, implement the rest, and you may want to compromise (I won’t be doing compat for old versions etc.)
Here it is for deleting: Android-HSKFlashcardsWidget/app/src/main/java/fr/berliat/hskwidget/data/dao/AnkiNotesDAO.kt at master · licryle/Android-HSKFlashcardsWidget · GitHub
The reference in Anki’s code is here: Anki-Android/api/src/main/java/com/ichi2/anki/api/AddContentApi.kt at main · ankidroid/Anki-Android · GitHub
Note that deleting works but crashes Anki when opening the UI. Filed here: Anki-Android/issues/18294
I realized I pasted one of the wrong links – this is better to study available APIs.
Check out the functions:
fun update
fun insert
fun query
fun delete
/***************************************************************************************
* *
* Copyright (c) 2015 Frank Oltmanns <frank.oltmanns@gmail.com> *
* Copyright (c) 2015 Timothy Rae <timothy.rae@gmail.com> *
* Copyright (c) 2016 Mark Carter <mark@marcardar.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 3 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
package com.ichi2.anki.provider
This file has been truncated. show original
Would this allow for editing a note’s fields within a card template? Trying to figure out how to with the API.
Edit:
Apologies, got this mixed up with the javascript api.