Android - Internal Storage vs External Storage when App installed on SD Card

你离开我真会死。 提交于 2021-02-07 11:39:16

问题


I have an app which downloads large amounts of content (it varies between users but could be 200mb to 1GB or more).

Currently I save all of this content on External Storage as this is likely to be the area with the most space, such as an SD card. This works fine for the most part however there is a situation where this isn't necessarily ideal.

If the device has in built external storage, like most tablets, but also has an SD card slot, the external storage issue gets a little complicated. The app can be installed onto the SD card, but the content will be saved on the built in storage, not the external SD card.

If the app is install on an SD card, will calling getFilesDir() give a path on the SD card, or the internal storage?

And what is the best way of handling this? Should I save content to the internal storage (on an sd card), the external storage or is asking the user when starting the app the best idea?


回答1:


The app can be installed onto the SD card, but the content will be saved on the built in storage, not the external SD card.

No. If the device has external storage, the app will be installed to external storage. It does not matter whether the device also has an SD card.

If the app is install on an SD card, will calling getFilesDir() give a path on the SD card, or the internal storage?

getFilesDir() is always internal storage, regardless of where the app is installed.




回答2:


If the app is install on an SD card, will calling getFilesDir() give a path on the SD card, or the internal storage?

No. getFilesDir() method in Context class always returns path to Internal Storage(in Android terms).

In most cases, directory path returned by getFilesDir() would be /data/data/your.application.package.appname/files . But it may vary on different phones, different Android versions.

To store your app files in SD card, you may use File[] getExternalFilesDirs (String type) method in Context class. Generally, second returned path would be the storage path for microSD card (if any).

On my phone, second path returned was /storage/sdcard1/Android/data/your.application.package.appname/files after passing null as argument for getExternalFilesDirs (String type)

The Internal and External Storage terminology according to Google/official Android docs is quite different from what we think.



来源:https://stackoverflow.com/questions/10496320/android-internal-storage-vs-external-storage-when-app-installed-on-sd-card

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!