sd-card

Android how to use Environment.getExternalStorageDirectory()

依然范特西╮ 提交于 2019-11-26 00:28:29
问题 How can i use Environment.getExternalStorageDirectory() to read a a stored image from the SD card or is there a better way to do it? 回答1: Environment.getExternalStorageDirectory().getAbsolutePath() Gives you the full path the SDCard. You can then do normal File I/O operations using standard Java. Here's a simple example for writing a file: String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath(); String fileName = "myFile.txt"; // Not sure if the / is on the path or not

Find location of a removable SD card

偶尔善良 提交于 2019-11-25 22:18:24
问题 Is there an universal way to find the location of an external SD card? Please, do not be confused with External Storage. Environment.getExternalStorageState() returns the path to the internal SD mount point, like \"/mnt/sdcard\". But the question is about the external SD. How do I get a path like \"/mnt/sdcard/external_sd\" (it may differ from device to device)? I guess I will end with filtering of the output of the mount command by filesystem name. But I\'m not sure this way is robust enough

How do I backup a database file to the SD card on Android?

[亡魂溺海] 提交于 2019-11-25 18:55:21
I'd like to add a feature to my Android app that automatically backs up the SQLite database to the SD card . What's the best way to go about this? Are any examples or tutorials available? SQLite databases are completely self-contained files and are portable — you can just copy the entire file straight to the SD card. Though first I'd check whether an SD card is installed in the device, and what its path is (using Environment.getExternalStorageDirectory() ). skeniver This code works for me! try { File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if