This is a Java library used to interact with AnkiConnect.
Add the dependency using Jitpack:
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
// Specific version
implementation 'com.github.caseyscarborough:ankiconnect-java:<version>'
// Master branch (latest)
implementation 'com.github.caseyscarborough:ankiconnect-java:master-SNAPSHOT'
}
All method names in the library correspond to the actions in the AnkiConnect API and documentation to keep the usage straightforward.
// Default client using localhost:8765
AnkiConnect ankiconnect = new AnkiConnect();
// Specify the host and port
AnkiConnect ankiconnect = new AnkiConnect("localhost", 8765);
// Specify an API key
AnkiConnect ankiconnect = new AnkiConnect("localhost", 8765, "my-api-key");
Find cards based on a search query. The search query is the same as the ones used in the Anki desktop client.
List<Long> ids = ankiconnect.findCards("deck:Default");
More information about the search query can be found here.
Retrieve information about a list of cards.
List<Long> ids = ankiconnect.findCards("is:suspended");
List<Card> cards = ankiconnect.cardsInfo(ids);
Retrieve a list of reviews for one or more cards.
// Get reviews for a single cards
List<Review> reviews = ankiconnect.getReviewsOfCard(124248248824L);
// Get reviews for multiple cards
List<Long> ids = ankiconnect.findCards("deck:*");
Map<Long, List<Review>> reviewMap = ankiconnect.cardsReviewInfo(ids);