Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

外付けSDカードにデータを保存

More than 5 years have passed since last update.

そもそも

Androidは外部SDに保存するパスがバラバラなので、あまり外部ストレージに保存するのは推奨されない。それでも保存したい時の話。
http://techbooster.org/android/application/16004/

内部ストレージのパス

内部ストレージへのパスは
Environment.getExternalStorageDirectory()
メソッドで取得する。(メソッド名は外部っぽいけど内部)

端末の外部ストレージのパス取得

端末を繋いだ状態でAndroid Studioのナビバーのドロイドくんをクリックし、Android Device Monitorを起動

/system/etc/vold.fstab を保存書き出ししてファイルをエディタで開く。

# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# NOTE: This file has been modified by Sony Mobile Communications AB.
# Modifications are licensed under the licence above.

dev_mount ext_card /storage/sdcard1 auto /devices/platform/msm_sdcc.3/mmc_host
dev_mount usbdisk /storage/usbdisk auto /devices/platform/msm_hsusb_host

最後の2行に外部ストレージのパスが書いてある。
この端末の場合
/storage/sdcard1 ← MicroSD
/storage/usbdisk ← USB Port

となる。

あとは内部ストレージと同じように使える。

参考)
http://nobuo-create.net/sdcard-2/

ryusukefuda
CTO 海外テック情報を毎週配信するニュースレターやってます。 https://www.ryusukefuda.com/
https://www.ryusukefuda.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away