Detecting if SD card present or not always returns true

一笑奈何 提交于 2019-12-31 06:59:28

问题


I am developing an android app, where i am trying to check if SD card is present or not to perform a specfic task.I am using the code from the below link to check it.

Check whether the SD card is available or not programmatically

The problem is , the code is working fine for many of my phones, but on my Galaxy S , even if i dont have a SD card, the isSDcardpresent is always a true.

Not sure what the problem is, Please help! Thanks!


回答1:


There is always an 'external' storage directory, even for device without SD card, see getExternalStorageDirectory :

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

It may also not be the real SD card, see Data storage guide :

It's possible that a device using a partition of the internal storage for the external storage may also offer an SD card slot. In this case, the SD card is not part of the external storage and your app cannot access it (the extra storage is intended only for user-provided media that the system scans).

I think the question 'is the SD card present ?' should be translated to 'is the shared directory available ?'.



来源:https://stackoverflow.com/questions/18382444/detecting-if-sd-card-present-or-not-always-returns-true

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