android取sd卡路徑
① 安卓手機如何讀取外置sd卡
系統會自動讀取插入的外置sd卡里的文件內容,你打開手機的文件管理器,在文件類型欄里點任意一種類型,比如視頻,你就能看到sd卡里所有的視頻文件了。
② 安卓手機sd卡的路徑在哪
sd卡路徑的確是在/mnt sdcard,不過請注意下載游戲安裝玩是無法安裝在sd卡里,也就是說你安裝了還是在手機內存里,游戲運行時是佔用手機內存的,建議你試試用電腦把數據包下載在手機sd卡里,如果還是提醒內存不足就卸載掉點東西吧。
(2)android取sd卡路徑擴展閱讀:
SD存儲卡是一種基於半導體快閃記憶器的新一代記憶設備,由於它體積小、數據傳輸速度快、可熱插拔等優良的特性,被廣泛地於攜帶型裝置上使用,例如數碼相機、個人數碼助理(外語縮寫PDA)和多媒體播放器等。
SD卡是由松下電器、東芝和SanDisk聯合推出,1999年8月發布。SD卡的數據傳送和物理規范由MMC發展而來,大小和MMC卡差不多,尺寸為32mm x 24mm x 2.1mm。長寬和MMC卡一樣,只是比MMC卡厚了0.7mm,以容納更大容量的存貯單元。
S與 MMC 卡保持著向上的兼容,MMC卡可以被新的SD設備存取,兼容性則取決於應用軟體,但SD卡卻不可以被MMC設備存取。
參考資料:SD卡-網路
③ android怎麼獲sd卡內的所有文件目錄
android程序獲取SD卡目錄的方法如下:
手機通過數據線連接電腦端,在計算機里會顯示兩個磁碟,一個是系統內存,另外一個就是SD卡內存,打開SD卡就可以找到文件目錄。
也可以通過手機查找,打開手機應用程序,點擊文件管理打開,然後打開所有文件。
接著打開」extSdCard「文件夾就是SD卡里的目錄了。
④ android怎麼獲取sdcard文件
啟動eclipse,新建Android工程(具體創建方法,請參考筆者之前所寫經驗《如何建Android工程》);
找到res--》layout--》activity_main.xml,雙擊點開
從面板中拖兩個button到界面上,分別命名:
getDIR(此button用於示範獲取到的sdcard路徑)
dir創建新文件夾(此button用於示範在sdcard路徑下新建文件夾)
對button分辨綁定點擊事件
//獲取sdcard路徑
public void getDIR(View v){
String sdpath = Environment.getExternalStorageDirectory().toString();
AlertDialog.Builder build = new Builder(this);
build.setMessage(sdpath).show();
}
//在手機sdcard路徑下新建名為jingyan的文件夾
public void newPackage(View v){
String mkdir = Environment.getExternalStorageDirectory()+"/jingyan/test.txt";
File file = new File(mkdir);
AlertDialog.Builder build = new Builder(this);
if(file.exists()){
build.setMessage("文件夾已存在").show();
}else{
file.mkdirs();
build.setMessage("新建成功").show();
}
}
在【AndroidManifest.xml】配置文件中添加app對文件的操作許可權
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
點擊getDIR--》彈出sdcard路徑
點擊dir創建新文件夾--》
如果文件夾已存在,則提示「文件夾已存在」
反之,則提示"新建成功",同時在手機sdcard中可以找到新建成功的文件夾
⑤ 如何讀取SD卡CSV文件或指定的路徑在android系統
android手機獲取自帶存儲路徑和sd卡存儲路徑的方式是:調用Environment.getExternalStorageDirectory(),返回的存儲目錄並不是系統內置的SD卡目錄。
1.一部分手機將eMMC存儲掛載到 /mnt/external_sd 、/mnt/sdcard2 等節點,而將外置的SD卡掛載到 Environment.getExternalStorageDirectory()這個結點。
此時,調用Environment.getExternalStorageDirectory(),則返回外置的SD的路徑。
2.而另一部分手機直接將eMMC存儲掛載在Environment.getExternalStorageDirectory()這個節點,而將真正的外置SD卡掛載到/mnt/external_sd、/mnt/sdcard2 等節點。
此時,調用Environment.getExternalStorageDirectory(),則返回內置的SD的路徑。
⑥ android開發想得到sd卡路徑
通過正規api得不到外卡路徑.
谷歌在源碼中給出了得到外卡路徑的方法,但標記為隱藏介面,因此api無法訪問.
可以通過反射介面得到:
java">importjava.lang.reflect.Method;
importandroid.os.storage.StorageManager;
(){
try{
StorageManagersm=(StorageManager)getSystemService(STORAGE_SERVICE);
MethodgetVolumePathsMethod=StorageManager.class.getMethod("getVolumePaths",null);
String[]paths=(String[])getVolumePathsMethod.invoke(sm,null);
//firstelementinpaths[]isprimarystoragepath
returnpaths[0];
}catch(Exceptione){
Log.e(TAG,"getPrimaryStoragePath()failed",e);
}
returnnull;
}
(){
try{
StorageManagersm=(StorageManager)getSystemService(STORAGE_SERVICE);
MethodgetVolumePathsMethod=StorageManager.class.getMethod("getVolumePaths",null);
String[]paths=(String[])getVolumePathsMethod.invoke(sm,null);
//secondelementinpaths[]issecondarystoragepath
returnpaths[1];
}catch(Exceptione){
Log.e(TAG,"getSecondaryStoragePath()failed",e);
}
returnnull;
}
publicStringgetStorageState(Stringpath){
try{
StorageManagersm=(StorageManager)getSystemService(STORAGE_SERVICE);
MethodgetVolumeStateMethod=StorageManager.class.getMethod("getVolumeState",newClass[]{String.class});
Stringstate=(String)getVolumeStateMethod.invoke(sm,path);
returnstate;
}catch(Exceptione){
Log.e(TAG,"getStorageState()failed",e);
}
returnnull;
}
如果樓主有源碼,可以去找StorageManager這個類,拉到文件最下方,就可以看到那三個隱藏介面.
⑦ Android開發如果有SD卡1SD卡2,怎麼獲得兩個路徑
獲得Android開發如果有SD卡1SD卡2的辦法有:
1,輸入:sdCardDir = Environment.getExternalStorageDirectory();獲取的不是sd卡路徑
2,一個是手機內存sdcard0,一個是sd卡sdcard1。一個是內置,一個是外置的
內置即買手機時說的xxG
3,Environment.getExternalStorageDirectory()這個只是獲取一個外置sd卡。但是4.0以後很多手機rom很大了且有些根本不需要外置sd卡了,於是安卓4.0後就會把機身內存rom還劃分一部分當作外置sd卡使用,而且這個Environment.getExternalStorageDirectory()不同的手機廠商獲取的目錄名字可能不同哦大部分是/mnt/sdcard,不過你完全可以當作「外置sd卡使用了
⑧ Android SD卡路徑問題以及如何獲取SDCard 內存詳解
較好的方法是通過Environment
來獲取路徑,最後給出一個例子,教你怎樣獲取SDCard
的內存,顯示出來告訴用戶。講述的內容如下:0202
0、獲取sd卡路徑。
1、講述
Environment
類。
2、講述
StatFs
類。
3、完整例子讀取
SDCard
內存
0、獲取sd卡路徑
方法一:
private
String
folder
=
"/sdcard/DCIM/Camera/"(SD卡上拍照程序的圖片存儲路徑);
//寫死絕對路徑,不贊成使用方法二:
⑨ 如何正確獲得Android內置SD卡跟外置可插拔SD卡
參考如下內容:
/內置sd卡路徑
String sdcardPath = System.getenv("EXTERNAL_STORAGE");
//內置sd卡路徑
String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath();
//外置置sd卡路徑
String extSdcardPath = System.getenv("SECONDARY_STORAGE");
在Enviroment類的源碼中獲得sd卡路徑其實也是通過 System.getnv() 方法來實現的,如隱藏的方法:
/** {@hide} */
public static File () {
return new File(System.getenv(ENV_EXTERNAL_STORAGE));
}
註:更詳細的內容還是去看Enviroment源碼。
另外要注意的是,在API 23版本中 SECONDARY_STORAGE 被移除。
⑩ 如何正確獲得Android內外SD卡路徑
/**
* 獲取手機自身內存路徑
*
*/
public static String getPhoneCardPath(){
return Environment.getDataDirectory().getPath();
}
/**
* 獲取sd卡路徑
* 雙sd卡時,根據」設置「裡面的數據存儲位置選擇,獲得的是內置sd卡或外置sd卡
* @return
*/
public static String getNormalSDCardPath(){
return Environment.getExternalStorageDirectory().getPath();
}
/**
* 獲取sd卡路徑
* 雙sd卡時,獲得的是外置sd卡
* @return
*/
public static String getSDCardPath() {
String cmd = "cat /proc/mounts";
Runtime run = Runtime.getRuntime();// 返回與當前 Java 應用程序相關的運行時對象
BufferedInputStream in=null;
BufferedReader inBr=null;
try {
Process p = run.exec(cmd);// 啟動另一個進程來執行命令
in = new BufferedInputStream(p.getInputStream());
inBr = new BufferedReader(new InputStreamReader(in));
String lineStr;
while ((lineStr = inBr.readLine()) != null) {
// 獲得命令執行後在控制台的輸出信息
Log.i("CommonUtil:getSDCardPath", lineStr);
if (lineStr.contains("sdcard")
&& lineStr.contains(".android_secure")) {
String[] strArray = lineStr.split(" ");
if (strArray != null && strArray.length >= 5) {
String result = strArray[1].replace("/.android_secure",
"");
return result;
}
}
// 檢查命令是否執行失敗。
if (p.waitFor() != 0 && p.exitValue() == 1) {
// p.exitValue()==0表示正常結束,1:非正常結束
Log.e("CommonUtil:getSDCardPath", "命令執行失敗!");
}
}
} catch (Exception e) {
Log.e("CommonUtil:getSDCardPath", e.toString());
//return Environment.getExternalStorageDirectory().getPath();
}finally{
try {
if(in!=null){
in.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if(inBr!=null){
inBr.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return Environment.getExternalStorageDirectory().getPath();
}
//查看所有的sd路徑
public String getSDCardPathEx(){
String mount = new String();
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("secure")) continue;
if (line.contains("asec")) continue;
if (line.contains("fat")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
mount = mount.concat("*" + columns[1] + "\n");
}
} else if (line.contains("fuse")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
mount = mount.concat(columns[1] + "\n");
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mount;
}
//獲取當前路徑,可用空間
public static long getAvailableSize(String path){
try{
File base = new File(path);
StatFs stat = new StatFs(base.getPath());
long nAvailableCount = stat.getBlockSize() * ((long) stat.getAvailableBlocks());
return nAvailableCount;
}catch(Exception e){
e.printStackTrace();
}
return 0;
}