diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java index 7640c57b4256..8bda5898a17d 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java @@ -4221,6 +4221,17 @@ public void ankiAddTagToCard() { runOnUiThread(() -> showTagsDialog()); } + @JavascriptInterface + public void ankiSearchCard(String query) { + Intent intent = new Intent(AbstractFlashcardViewer.this, CardBrowser.class); + Long currentCardId = getCurrentCardId(); + if (currentCardId != null) { + intent.putExtra("currentCard", currentCardId); + } + intent.putExtra("search_query", query); + startActivityForResultWithAnimation(intent, REQUEST_BROWSE_CARDS, START); + } + @JavascriptInterface public boolean ankiIsActiveNetworkMetered() { try { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java index 6d0ec45a67b8..8f9f900c20af 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java @@ -598,6 +598,12 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.card_browser); initNavigationDrawer(findViewById(android.R.id.content)); startLoadingCollection(); + + // for intent coming from search query js api + if (getIntent().getStringExtra("search_query") != null) { + mSearchTerms = getIntent().getStringExtra("search_query"); + searchCards(); + } }