Add a new note using AnkiDroid API with shell commands


Is it possible to use the AnkiDroid API with shell commands (like abd or termux) ?

Reading the AnkiDroid API, I saw an example of triggering sync action with a command:

am start -a 'com.ichi2.anki.DO_SYNC'

It leads me to this command to add the first two fields of a new note:

am start -a android.intent.action.SEND -p com.itch2.anki -t "text/plain" -e android.intent.extra.TEXT "first field" -e android.intent.extra.SUBJECT "second one"

I don’t think I can select the note type and add more fields … I would like to do something like this Java code in the docs:

api.addNote(modelId, deckId, new String[] {"日の出", "sunrise"}, null);

But using only the command-line … is this even possible ?

1 Like


It’s been a long while since I’ve actively looked into the intent-based API.

I suspect that what you want to do isn’t currently possible with AnkiDroid

It’s worth seeing if you could open the Note Editor with the above intent, then send a Ctrl+Enter keyboard shortcut to add the note.

Here is a full list of keyboard shortcuts, please let me know if you want more added to the 2.18 alpha:

If this is too flaky, you can create a small app which uses the AnkiDroid API to handle this functionality:

  • Listen for an Intent
  • Obtain the fields from the intent
  • Connect to AnkiDroid via our API and add the note using the above fields

Sample app:


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.