Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SD card changes in Android 4.4.2 make AnkiDroid inoperable #3106

Closed
hssm opened this issue Jul 28, 2015 · 28 comments
Closed

SD card changes in Android 4.4.2 make AnkiDroid inoperable #3106

hssm opened this issue Jul 28, 2015 · 28 comments
Labels
Bug Help Wanted Requesting Pull Requests from volunteers Priority-High Reproduced This bug has been reproduced by a maintainer Stale

Comments

@hssm
Copy link
Member

hssm commented Jul 28, 2015

Originally reported on Google Code with ID 2209

Here is a link with more details about the changes: http://www.androidcentral.com/kitkat-sdcard-changes

I've had a user report two Samsung devices that are now unable to use AnkiDroid after
they both got updated to Android 4.4.2:
Note 2 on 4.4.2, exFAT 64GB SD
Note 10 on 4.4.2, FAT 16GB SD

Also a couple screenshots that show what happens when downloading a collection or opening
an existing one.

I believe so far we have only tested 4.4.2 on Nexus devices which only have internal
storage so we never caught this.

Reported by Houssam.Salem.Au on 2014-07-24 11:59:33


- _Attachment: [2.jpg](https://storage.googleapis.com/google-code-attachments/ankidroid/issue-2209/comment-0/2.jpg)_
@hssm hssm added Priority-High Bug Accepted Maintainers welcome a PR implementing this feature labels Jul 28, 2015
@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Reported by Houssam.Salem.Au on 2014-07-24 12:00:04


- _Attachment: [1.jpg](https://storage.googleapis.com/google-code-attachments/ankidroid/issue-2209/comment-1/1.jpg)_

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Issue 2260 has been merged into this issue.

Reported by perceptualchaos2 on 2014-09-01 02:20:34

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Issue 2259 has been merged into this issue.

Reported by perceptualchaos2 on 2014-09-01 02:21:28

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

See issue #67570. Can't write anything to external sd card.

Reported by ravip005 on 2014-11-01 15:08:40

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

I thought something was up. When the deck doesn't work on my phone, I usually load the
deck on the computer and check database there to make it work on my phone. This time,
that didn't work. Then I tried to copy the default AnkiDroid directory that comes with
a fresh install to my sdcard and changed the location of the deck to point to that.
Even that didn't work. I looked at issue #67570 and a project member posted the following.
When will AnkiDroid be updated to let us read and write to our decks located on our
SD cards? I guess for now, I will just settle for desktop Anki.

Hey all, in KitKat we introduced APIs that let apps read/write file in app-specific
directories on secondary storage devices, such as SD cards.

We heard loud and clear that developers wanted richer access beyond these directories,
so in Lollipop we added the new ACTION_OPEN_DOCUMENT_TREE intent.  Apps can launch
this intent to pick and return a directory from any supported DocumentProvider, including
any of the shared storage supported by the device.  Apps can then create, update, and
delete files and directories anywhere under the picked tree without any additional
user interaction.  Just like the other document intents, apps can persist this access
across reboots.

This gives apps broad, powerful access to manage files while still involving the user
in the initial selection process.  Users may choose to give your app access to a narrow
directory like “My Vacation Photos,” or they could pick the top-level of an entire
SD card; the choice is theirs.

To make it easy for developers to transition to these new APIs, there’s a new DocumentFile
support library class.  It looks and feels just like a traditional java.lang.File object,
which makes it easy to adapt existing code:

http://developer.android.com/reference/android/support/v4/provider/DocumentFile.html

These new APIs aren’t just limited to shared storage; they can be used with any DocumentsProvider
that adds support for Root.FLAG_SUPPORTS_IS_CHILD, such as the advanced Vault example:

https://android.googlesource.com/platform/development/+/android-5.0.0_r2/samples/Vault/src/com/example/android/vault/VaultProvider.java#258

If you're an end user, please reach out to app developers to ask them to start using
these new APIs.  With these new rich APIs in place, this issue is considered fixed.

http://code.google.com/p/android/issues/detail?id=67570

Reported by christopher.upapong on 2014-11-17 02:42:22

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Thanks for the info, I wasn't aware of this new API!

Reported by perceptualchaos2 on 2014-11-17 05:39:30

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

I figured out a workaround and successfully moved AnkiDroid folder to external SD card
on my unrooted hTC Desire 820.

Here are the steps:
1. Find the package name of AnkiDroid apk: Since the name of current version AnkiDroid
apk is "com.ichi2.anki-2.apk", the package name is "com.ichi2.anki"

2. Go to your external SD card folder via file management app and create a folder with
the apk's package name containing an AnkiDroid sub-folder: the exact path depends on
your devices. 
E.g. On my Desire 820, the path of the external SD card folder is "/storage/ext_sd/",
and after I created the folders the complete path of the AnkiDroid folder is "/storage/ext_sd/Android/data/com.ichi2.anki/AnkiDroid/"

3. Install AnkiDroid, open it, and change the storage path to the path I mentioned
above.

4. Enjoy the benefits AnkiDroid brings to you!!

Reported by hidelensman on 2014-12-01 14:02:03

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

^^^That seems to work... Thanks!

Reported by bryanwithay1986 on 2014-12-05 13:02:56

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

On a Sony Xperia Z1 manually creating the folder on the external sd-card didn't work.
You have to rename the folder on the internal storage (presumably AnkiDroid) to match
Ankidroid's package name: com.ichi2.anki and move the folder to the external sd-card
using File Commander (Default system app on Sony devices with root permissions). Afterwards
change the storage path in the settings to /storage/sdcard1/Android/data/com.ichi2.anki

Reported by chris.yereaztian on 2014-12-28 13:53:41

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Issue 2588 has been merged into this issue.

Reported by perceptualchaos2 on 2015-04-23 00:02:15

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Issue 2620 has been merged into this issue.

Reported by perceptualchaos2 on 2015-05-25 00:31:05

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Issue 2660 has been merged into this issue.

Reported by perceptualchaos2 on 2015-06-22 01:33:12

@timrae timrae added the Help Wanted Requesting Pull Requests from volunteers label Oct 28, 2015
@gbriel-almeida-santos
Copy link

hssm, I did what you said "/storage/NAME_SD/Android/data/com.ichi2.anki/AnkiDroid/". first it worked, but when I was syncing my collection another error appeared. Then I deleted my anki e reinstalled it, and now the path is not valid.

I tried the second method too, but didn't work.

My Android is 5.0.2.
In my old smartphone with Android JellyBean, the change of path woks normally.

@mijascuric
Copy link

Hi,

Currently my AnkiDroid collection and backup is stored on my device storage. I would like to move it to external SD card.

I was looking at the directions above but I am not able to find apk "com.ichi2.anki-2.apk" or the package name is "com.ichi2.anki".

The collection path on my phone is /sdcard/AnkiDroid.

Can I just move all the subfolders from my device storage AnkiDroid folder to newly created AnkiDroid folder in sdcard?

My Adroid version is 5.0 on Samsung Galaxy Active.

Thanks,

@timrae
Copy link
Member

timrae commented Feb 4, 2016

Sorry we can't provide support on this issue, and we strongly recommend not to use external SD card. If you choose to ignore our advice then you're basically on your own, though you can probably find help on sites like forum.xda-developers.com and android.stackexchange.com

@LucasCoder
Copy link

What a bunch of lazy devs to not support such a basic feature.

@wareya
Copy link

wareya commented Oct 14, 2016

Just for reference, when I add an SD card, my device treats the SD card as internal storage and the internal storage as an SD card. I don't think SD cards can officially be formatted with anything that supports more characters than UCS-2, so this actually made it so that I couldn't use (without modification) a deck that had media filenames with characters in supplemental planes (i.e. extended kangxi radicals).

@weakedsick03
Copy link

the one for sony xperia worked for me. Thank you very much

On a Sony Xperia Z1 manually creating the folder on the external sd-card didn't work.
You have to rename the folder on the internal storage (presumably AnkiDroid) to match
Ankidroid's package name: com.ichi2.anki and move the folder to the external sd-card
using File Commander (Default system app on Sony devices with root permissions). Afterwards
change the storage path in the settings to /storage/sdcard1/Android/data/com.ichi2.anki

Reported by chris.yereaztian on 2014-12-28 13:53:41

@gadamiak
Copy link

gadamiak commented Dec 1, 2016

A workaround with creating a com.ichi2.anki folder worked for me on Android 6. My path is /storage/<XXXX-XXXX>/Android/data/com.ichi2.anki/AnkiDroid/.

Anyway, ability to store app data on external SD card is quite a standard feature and lack of it may be a showstopper for using the app. One big deck will fill up whole left space on most 8GB devices forcing users to uninstall other applications. It should definitely be possible to select external storage for data.

@tf0054
Copy link

tf0054 commented Apr 19, 2017

On android 7.0, we could change the storage to "External storage" via Settings/Applications. After this change, I guess we could set the AnkiDroid directory to /storage/<XXXX-XXXX>/Android/data/com.ichi2.anki/AnkiDroid/ via "Advanced Preference" in the menu.
(I am using on Galaxy S7)

But we definitely know this way is workaround and I hope this difficulty would be changed.

@timrae timrae added Reproduced This bug has been reproduced by a maintainer and removed Accepted Maintainers welcome a PR implementing this feature labels Jan 3, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2020

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

@sudomain
Copy link
Contributor

I realize this is an old and closed issue, but I'm hoping to gain understanding why SD cards are not supported. Please don't interpret this comment the wrong way: I'm positive the devs have good reason to not support the feature, I just wish to know why.

A few possible reasons that I'm not sure of because I don't have a lot of Android dev experience:

  1. Maybe there isn't a reliable way to use SD card storage across the different device manufacturers and Android versions? It seems storage is changing again with Enhancement: AnkiDroid should not use Storage permission (Deadline November 2021) #5304
  2. The collection.anki2 file is a Sqlite database that seems to get written to every time the app is opened. SD cards typically have fewer write cycles than the technology typically used for internal flash

Can one of the devs please confirm or provide insight why I'm wrong?

@mikehardy
Copy link
Member

Your point 1 is correct in that external storage in general is really hard to work with across the android API skew (more than vendor skew), and with the move to scoped storage, there is just not really time for us to handle the support load that comes in with custom paths and custom external storage setups. Go ahead and do it, you're just on you're own...

Point 2 is not something I think we cared about much. It was purely that the support load was really high and soaked up scarce developer time for a real niche audience that has only grown smaller as more phones don't even support external cards at all now and more phones have enough space now it is not as pressing.

I'm always keen to mention that I live in a country where most people actually do have space constraints so it would be great to have easier support for it, but then as a contributor I can only say that the experience in the project was such that it ate up too much time with regard to support to continue it

@david-allison
Copy link
Member

david-allison commented Sep 21, 2021

They were unsupported before I joined. I'm willing to question the status-quo and state that I don't know, but I don't have the time to take this on. Unsupported also means "they work if you change the path, but we don't provide support for issues".

You can probably find some history from older threads about this.

Point 3: Having an SD card allows the user to eject the card whilst the application is running, this can lead to (unavoidable) issues.

Point 4: SD cards can be badly formatted (FAT32 + AnkiDroid users can have more than 65,534 files in their collection.media). This could easily be the cause of why a few of the AnKing decks don't work on AnkiDroid (they give a badly formatted unicode error which I haven't been able to reproduce)

AnkiDroid handles the Android lifecycle fairly badly here (we have the Android lifecycle PLUS onCollectionLoaded handling PLUS SD Card ejection detection), which is done in a nonstandard per-activity basis.

If I were to fix/improve things, I'd want to use it as an excuse to tackle the lifecycle issues, which is a very big job in itself

@sudomain
Copy link
Contributor

Thank for the detailed replies. Some of this comment could be in my feature request(#9532 ) but is here because it ties with this discussion too.

I'm always keen to mention that I live in a country where most people actually do have space constraints...

I'm in an US metropolitan area and I'm (very) fortunate enough to be able to afford a device with storage that is "the next size up" from my current device. At the same time, I'm willing to pay a bounty for the SD feature equivalent to the price of this new device ($30 USD). This would be my first feature bounty offered, so I apologize if that amount is paltry.

Go ahead and do it, you're just on you're own...

To be clear- if I manage to implement it myself or pay someone else to, do you wish for a PR? Or shall I keep it in a fork? Like you said it would be another thing to maintain, even after initial implementation. At the same time, the number of people that would benefit decreases as phones with larger capacities become cheaper. Also, (IIRC) There used to be hesitation to adding more settings to the app.

Point 3: Having an SD card allows the user to eject the card whilst the application is running, this can lead to (unavoidable) issues.

Good point. However, if users are technically savvy enough to go into Advanced settings and change a path to somewhere on their SD card, I'd hope they be able to realise removing it causes their media to disappear :).

Point 4: SD cards can be badly formatted (FAT32 + AnkiDroid users can have more than 65,534 files in their collection.media). This could easily be the cause of why a few of the AnKing decks don't work on AnkiDroid (they give a badly formatted unicode error which I haven't been able to reproduce)

Referring to #8148 ? I think 99℅ of my collection.media comes from two AnKing mega decks- AnKing and AnKing MCAT and I've got ~36,000 files: (please ignore my use of ls in a pipe :)

$ ls /storage/A313-660E/Android/data/com.ichi2.anki/collection/collection.media | wc
36263 81252 1113904

@david-allison
Copy link
Member

Yep - there's a hard limit of 65k files per directory in FAT32, which is a more pressing issue than the #8148 issue (which I can't reproduce on my Android).

@mikehardy
Copy link
Member

Still, with regard to filesystem formats, that's probably something we can detect, looked at as an engineering problem. Similar to our "we can't expand this zip file because there's no space" check. We can check for files vs formats and do something. Anyway, I'm totally fine maintaining it as an option (that is: supported in code) I would just continue it's "go ahead and use the feature but please don't ask for support" status. People losing collections is a tragedy, and being very very explicit that it can happen and we will probably not be able to help is the right expectation to set.

@Fabiensk
Copy link

Fabiensk commented Sep 15, 2024

A workaround with creating a com.ichi2.anki folder worked for me on Android 6. My path is /storage/<XXXX-XXXX>/Android/data/com.ichi2.anki/AnkiDroid/.

I have a old Galaxy S5 mini (Android 6.0.1) which becomes very slow if I don't add a SD-card (because of lack of internal storage). Using the tip above was the only way I could store my Anki files on the SD-card. I use this old phone as a Anki-phone (it's small enough so I can hold it and anki while running).
After a restart, AnkiDroid could not access to this directory. So I had to use the default location in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Help Wanted Requesting Pull Requests from volunteers Priority-High Reproduced This bug has been reproduced by a maintainer Stale
Projects
None yet
Development

No branches or pull requests