Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly identify the file storage directory of AnkiDroid (or any other external app) from my application?

Tags:

android

anki

I use AnkiDroid API to create and send cards to AnkiDroid application (https://github.com/ankidroid/Anki-Android/wiki/AnkiDroid-API). But there is one issue connected to sending media files via API. They are stored in the external storage, "/storage/emulated/0/AnkiDroid" in my case. I can add and read files from there, but I think this path may be different for other devices or in case if I switch to SD card. Question: how to correctly identify the path to application's external storage directory?

like image 669
snailp4el Avatar asked Nov 18 '25 06:11

snailp4el


1 Answers

Ex-AnkiDroid project maintainer here.

The path you have is the default path to the AnkiDroid media files.

AnkiDroid users can modify this path via configuration, as you probably know:

enter image description here

This setting is stored using Android's usual settings storage technology, which for security reasons is not accessible to other apps.

I don't think the property is currently exposed to other apps (source code), but that is a valid use case so please create a new issue at https://github.com/ankidroid/Anki-Android/issues

Meanwhile, and to be compatible with current and prior versions of AnkiDroid, I would say you have two options:

  • Scan the SD card looking for a called collection.media. This folder is inside the AnkiDroid folder, and its name can not be changed, by convention. If you find several, compare last modification dates and ask the user.
  • Have a setting similar to the one in the screenshot above. Users who want to use a non-default folder will have to set it up in both apps, which is a bit inconvenient but not such a crazy thing to ask for.
like image 137
Nicolas Raoul Avatar answered Nov 19 '25 22:11

Nicolas Raoul