當前位置:首頁 » 安卓系統 » androidsd路徑獲取

androidsd路徑獲取

發布時間: 2023-01-03 16:40:55

『壹』 如何正確獲得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;
}

『貳』 Android開發中,獲取U盤或SD卡路徑。

@SuppressLint("PrivateApi")

    private String getStoragePath(Context context, boolean isUsb){

        String path="";

        StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);

        Class<?> volumeInfoClazz;

        Class<?> diskInfoClaszz;

        try {

            volumeInfoClazz = Class.forName("android.os.storage.VolumeInfo");

            diskInfoClaszz = Class.forName("android.os.storage.DiskInfo");

            Method StorageManager_getVolumes=Class.forName("android.os.storage.StorageManager").getMethod("getVolumes");

            Method VolumeInfo_GetDisk = volumeInfoClazz.getMethod("getDisk");

            Method VolumeInfo_GetPath = volumeInfoClazz.getMethod("getPath");

            Method DiskInfo_IsUsb = diskInfoClaszz.getMethod("isUsb");

            Method DiskInfo_IsSd = diskInfoClaszz.getMethod("isSd");

            List<Object> List_VolumeInfo = (List<Object>) StorageManager_getVolumes.invoke(mStorageManager);

            assert List_VolumeInfo != null;

            for(int i=0; i<List_VolumeInfo.size(); i++){

                Object volumeInfo = List_VolumeInfo.get(i);

                Object diskInfo = VolumeInfo_GetDisk.invoke(volumeInfo);

                if(diskInfo==null)continue;

                boolean sd= (boolean) DiskInfo_IsSd.invoke(diskInfo);

                boolean usb= (boolean) DiskInfo_IsUsb.invoke(diskInfo);

                File file= (File) VolumeInfo_GetPath.invoke(volumeInfo);

                if(isUsb == usb){//usb

                    assert file != null;

                    path=file.getAbsolutePath();

                }else if(!isUsb == sd){//sd

                    assert file != null;

                    path=file.getAbsolutePath();

                }

            }

        } catch (Exception e) {

            YYLog.print(TAG, "[——————— ——————— Exception:"+e.getMessage()+"]");

            e.printStackTrace();

        }

        return path;

    }

『叄』 android開發內置存儲設備外置SD卡的路徑怎麼獲取

方法:1點擊手機的文件管理2點擊上方的本地選項3顯示內部儲存的是自帶儲存路徑,SD卡位sdcard的儲存路徑

『肆』 android怎麼獲sd卡內的所有文件目錄

android程序獲取SD卡目錄的方法如下:
手機通過數據線連接電腦端,在計算機里會顯示兩個磁碟,一個是系統內存,另外一個就是SD卡內存,打開SD卡就可以找到文件目錄。
也可以通過手機查找,打開手機應用程序,點擊文件管理打開,然後打開所有文件。
接著打開」extSdCard「文件夾就是SD卡里的目錄了。

『伍』 android開發想得到sd卡路徑

通過正規api得不到外卡路徑.

谷歌在源碼中給出了得到外卡路徑的方法,但標記為隱藏介面,因此api無法訪問.

可以通過反射介面得到:

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 幾種不同路徑的獲取方法

前兩個應用內部存儲通過 Context 來獲取, 第三個作為外部存儲是通過 Environment 類來獲取. 注釋為返回值.

  • /data/data/包名/

    context.getFilesDir(); // /data/data/包名/filescontext.getCacheDir(); // /data/data/包名/cache
  • /sdcard/Android/data/包名/

    context.getExternalFilesDir(); // /sdcard/Android/data/包名/filescontext.getExternalCacheDir(); // /sdcard/Android/data/包名/cache
  • /sdcard/xxx

    // /storage/emulated/0Environment.getExternalStorageDirectory();// /storage/emulated/0/DCIM, 另外還有MOVIE/MUSIC等很多種標准路徑Environment.(Environment.DIRECTORY_DCIM);
  • 注意, 根據源碼文檔中說明, 獲取外部存儲時, 有可能會因為各種問題導致獲取失敗, 建議先使用 getExternalStorageState 來判斷外部存儲狀態, 如果已掛載的話再存儲.

『柒』 獲取android手機的自帶存儲路徑和sdcard存儲路徑

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的路徑。

『捌』 xamarin怎樣獲取android外卡路徑

xamarin怎樣獲取android外卡路徑

一部分手機將eMMC存儲掛載到 /mnt/external_sd 、/mnt/sdcard2 等節點,而將外置的SD卡掛載到 Environment.getExternalStorageDirectory()這個結點。
此時,調用Environment.getExternalStorageDirectory(),則返回外置的SD的路徑。

android 怎樣動態的獲取sd卡路徑

鏈接電腦USB調試情況下,在電腦上有新的磁碟顯示,一個SD的,一個手機的,打開SD的就可以找各文件夾路徑

Android怎樣獲取外部存儲器路徑

讀寫sdcard上的文件
其中讀寫步驟按如下進行:
1、調用Environment的getExternalStorageState()方法判斷手機上是否插了sd卡,且應用程序具有讀寫SD卡的許可權,如下代碼將返回true
Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
2、調用Environment.getExternalStorageDirectory()方法來獲取外部存儲器,也就是SD卡的目錄,或者使用"/mnt/sdcard/"目錄
3、使用IO流操作SD卡上的文件
注意點:手機應該已插入SD卡,對於模擬器而言,可通過mksdcard命令來創建虛擬存儲卡
必須在AndroidManifest.xml上配置讀寫SD卡的許可權
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

我怎樣才能獲得外部SD卡路徑為Android 4.0 +

1. 我想你需要這個外部SD卡:
new File("/mnt/external_sd/")

new File("/mnt/extSdCard/")
你的情況......
在更換Environment.getExternalStorageDirectory()您的作品,應在MNT目錄優先和工作在那裡檢查什麼..
你鍵入選擇哪個SD卡
File storageDir = new File("/mnt/");
if(storageDir.isDirectory()){
String[] dirList = storageDir.list();
TODO some type of selecton method?
}

怎樣獲取class路徑

  • importjava.io.File;

  • publicclassFileTest{

  • publicstaticvoidmain(String[]args)throwsException{

  • System.out.println(Thread.currentThread().getContextClassLoader()

  • .getResource(""));

  • System.out.println(FileTest.class.getClassLoader().getResource(""));

  • System.out.println(ClassLoader.getSystemResource(""));

  • System.out.println(FileTest.class.getResource(""));

  • System.out.println(FileTest.class.getResource("/"));

  • Class文件所在路徑

  • System.out.println(newFile("/").getAbsolutePath());

  • System.out.println(System.getProperty("user.dir"));

  • System.out.println(System.getProperty("file.encoding"));

  • }

  • }

android 怎麼獲取相冊路徑

android手機4.2版本之前是一個方法,大於4.2版本又是一個方法。

注意:現在手機市場android版本2015面上半年平均4.4,現在是平均5.0了。

  1. before

    你網路一下,都能查到,很簡單.

  2. after

    private void startPickPhotoActivity() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.setType("image/*"); Or 'image/ jpeg '
    startActivityForResult(intent, RESULT_PICK_PHOTO_NORMAL);
    }

獲得圖片返回的路徑
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == RESULT_PICK_PHOTO_NORMAL) {
if (resultCode == RESULT_OK && data != null) {

選中圖片路徑

mFileName = MainActivity.getPath(getApplicationContext(),
data.getData());
if ("".equals(mFileName)) {
return;
}
Intent intent = new Intent(this, EditActivity.class);
intent.putExtra("pathName", mFileName);
startActivity(intent);
}
}
}
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String getPath(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
ExternalStorageProvider
if (UriUtils.isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/"
+ split[1];
}
}
DownloadsProvider
else if (UriUtils.isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content:downloads/public_downloads"),
Long.valueOf(id));
return UriUtils.getDataColumn(context, contentUri, null, null);
}
MediaProvider
else if (UriUtils.isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = MediaColumns._ID + "=?";
final String[] selectionArgs = new String[] { split[1] };
return UriUtils.getDataColumn(context, contentUri, selection,
selectionArgs);
}
}
MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {
Return the remote address
if (UriUtils.isGooglePhotosUri(uri))
return uri.getLastPathSegment();
return UriUtils.getDataColumn(context, uri, null, null);
}
File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}

如何獲取android sdcard路徑

Environment.getExternalStorageDirectory()

android怎麼獲取U盤路徑

用Re管理器進入/mnt/目錄一個一個找

android怎麼獲取分區路徑

我們可以在adb中使用df 來查看分區情況。

1、跨分區不能用 MV命令來拷貝。但是可以用CP命令。如PWD,當前目錄為:/data/local/tmp 。

此目錄下有個busybox和1.txt文件。則利用CP命令拷貝如下:./busybox cp1.txt /system.

2、Android的用戶組有 System, root, shell

3、怎麼樣才能操作分區。

分區操作是需要許可權的。一般來說System分區的許可權限製得比較嚴,Data分區限制比較嚴,用戶可以操作的目錄有local,app目錄。比如/data/local/tmp.

data分區常用目錄:app , system , data ,local,misc 其中system,local可以進入並使用ls等命令。data,app可以進入,但不能用ls命令。

data/data目錄:存放的是所有APK程序數據的目錄,每個APK對就一個自己的Data目錄,就是在data/data/目錄下,會產生一個跟Package一樣的目錄。如有一個APK,它的包名叫.test.hello則,在data/data/目錄下會有一個.test.hello的目錄,這個APK只能操作此目錄,不能操作其它APK的目錄.這個在LINUX下叫做用戶進程只能操作自己的進程目錄.

data/app目錄:用戶安裝的APK放在這里。我們如果把APK放入這個文件夾下面的話,就算安裝好了。這就叫靜默安裝。不用管APK文件裡面的lib目錄下的庫文件,系統會自動幫我們放入調用庫的。

data/system目錄下面有packages.xml ,packages.list,appwidgets.xml, 等等一些記錄手機安裝的軟體,Widget等信息。

data/misc目錄:保存WIFI帳號,VPN設置信息等。如保存了一個WIFI連接帳號,則此目錄下的WIFI目錄下面可以查看到。

system分區常用目錄: app , lib, xbin, bin , media,framework.

system/app目錄:存放系統自帶的APK。沒有測試過是否將APK放入到System/app目錄下,也是靜默安裝APK。?

system/lib目錄:存放APK程序用到的庫文件。

system/bin目錄和system/xbin目錄:存放的是shell命令。

system/framework目錄:啟用Android系統所用到框架,如一些jar文件。

4 Android下面的目錄都是有許可權的,要操作目錄都需要有此許可權才能操作,如果沒有,則使用chomd777來修改.如果是分區根目錄,如/data分區, /system分區.都沒有許可權,則需要重新掛載. 使用 mount -oremount XX

『玖』 android4.0後怎麼獲取sdcard的路徑(包括外置和內置的)

getExternalStorageDirectory()方法在4.0以後只能獲取內置SD卡路徑
外置SD卡
/**
* 獲取外置SD卡路徑
* @return 應該就一條記錄或空
*/
public List<string> getExtSDCardPath()
{
List<string> lResult = new ArrayList<string>();
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
if (line.contains("extSdCard"))
{
String [] arr = line.split(" ");
String path = arr[1];
File file = new File(path);
if (file.isDirectory())
{
lResult.add(path);
}
}
}
isr.close();
} catch (Exception e) {
}
return lResult;
}

List<string> extPaths = getExtSDCardPath();
for (String path : extPaths) {
log.append("外置SD卡路徑:" + path + "\r\n");
}

PS別忘記添加許可權,內外置SD卡的許可權在4.0以後是不一樣的

『拾』 安卓手機sd卡的路徑在哪

sd卡路徑的確是在/mnt sdcard,不過請注意下載游戲安裝玩是無法安裝在sd卡里,也就是說你安裝了還是在手機內存里,游戲運行時是佔用手機內存的,建議你試試用電腦把數據包下載在手機sd卡里,如果還是提醒內存不足就卸載掉點東西吧。

(10)androidsd路徑獲取擴展閱讀:

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卡-網路

熱點內容
三星usb存儲設備在哪 發布:2025-04-23 04:43:31 瀏覽:498
把什麼塗在密碼鎖上能看到密碼 發布:2025-04-23 04:29:40 瀏覽:242
sql2000密碼忘記 發布:2025-04-23 04:22:03 瀏覽:21
安卓手機退出應用怎麼絲滑 發布:2025-04-23 04:17:46 瀏覽:107
小米全盤加密 發布:2025-04-23 04:14:24 瀏覽:741
pac腳本代理伺服器地址 發布:2025-04-23 04:08:44 瀏覽:954
5g編程 發布:2025-04-23 03:59:14 瀏覽:293
kafka源碼分析 發布:2025-04-23 03:57:41 瀏覽:16
企鵝存儲罐 發布:2025-04-23 03:57:00 瀏覽:437
掛機怎樣做腳本 發布:2025-04-23 03:45:33 瀏覽:534