2011-08-12 2 views
2

장치에 두 개의 SD 카드가 있는지 확인하는 방법이 있습니까 ??Android : Dual SD 카드 감지 방법

편집 :

나는 순간에, 내부 스토리지 및 실제 외부 SD 카드를 구별 할 방법이 없다는 것을 발견했다. 삼성 갤럭시 탭 (7 인치)과 같은 일부 장치에서는 시스템이 내부 저장소 (일반적으로 16GB)를 외부 저장소로 사용합니다. 불행히도 내부 저장 장치와 secondar/external/sd-card 저장 장치를 구분할 방법이 없습니다. 누군가 허니 콤과 이전 버전의 경우 가능하다고 생각하면 여기에 적어주세요. 나는 그것을 증명할 것입니다.

답변

1

이중 SD 카드를 확인하는 방법이 있다고 생각하지 않지만 일부 장치에는 2 가지 유형의 외부 저장소가 있습니다. 예를 들어 일부 모토로라 장치에서는 내부 보조 저장소가 /sdcard-ext으로 액세스된다는 것을 알고 있습니다. 이 디렉토리가 있는지 확인할 수 있습니다. 보조 저장소가있는 다른 기기에서도 추가로 -ext을 사용하고 그에 따라 반응합니다.

+0

예, 그렇습니다. 내부 저장 장치를 SD 카드로 간주하는 특정 장치가 있습니다. sd 카드로 취급되는 내부 저장 장치와 실제 외부 sd 카드를 구별 할 수있는 방법을 자세히 설명 할 수 있습니까? – Farhan

+1

'Environment.isExternalStorageEmulated()'및'Environment.isExternalStorageRemovable()'을 살펴보십시오 - http://developer.android.com/reference/android/os/Environment.html을 참조하십시오. –

0

에뮬레이트 된 SD와 물리적 인 SD가 모두있는 장치가 있습니다. (예 : Sony Xperia Z). getExternalFilesDir (null)과 같은 메서드는 에뮬레이트 된 SD 카드를 반환하기 때문에 실제 SD 카드를 노출하지 않습니다. 다음 코드를 사용하여 실제 SD에 대한 디렉토리를 가져옵니다. 이 호출은 모든 마운트 포인트와 온라인 SD 카드를 반환합니다. 어떤 마운트 지점이 OFFLINE SD 카드 (있는 경우)를 가리키는 지 파악해야하지만 대부분의 경우 온라인 SD 카드에만 관심이 있습니다.

 public static boolean getMountPointsAndOnlineSDCardDirectories(ArrayList<String> mountPoints, ArrayList<String> sdCardsOnline) 
     { 
      boolean ok = true; 

      mountPoints.clear(); 
      sdCardsOnline.clear(); 

      try 
      {     
       // File that contains the filesystems to be mounted at system startup 
       FileInputStream fs = new FileInputStream("/etc/vold.fstab"); 
       DataInputStream in = new DataInputStream(fs); 
       BufferedReader br = new BufferedReader(new InputStreamReader(in)); 

       String line; 
       while ((line = br.readLine()) != null) 
       { 
        // Skip comments and empty lines 
        line = line.trim(); 
        if ((line.length() == 0) || (line.startsWith("#"))) continue; 

        // Fields are separated by whitespace 
        String[] parts = line.split("\\s+"); 
        if (parts.length >= 3) 
        { 
         // Add mountpoint 
         mountPoints.add(parts[2]); 
        } 
       } 

       in.close(); 
      } 
      catch (Exception e) 
      { 
       ok = false; 
       e.printStackTrace(); 
      } 

      try 
      {     

       // Pseudo file that holds the CURRENTLY mounted filesystems 
       FileInputStream fs = new FileInputStream("//proc/mounts"); 
       DataInputStream in = new DataInputStream(fs); 
       BufferedReader br = new BufferedReader(new InputStreamReader(in)); 

       String line; 
       while ((line = br.readLine()) != null) 
       { 
        // A sdcard would typically contain these... 
        if (line.toLowerCase().contains("dirsync") && line.toLowerCase().contains("fmask")) 
        { 
         String[] parts = line.split("\\s+"); 
         sdCardsOnline.add(parts[1]); 

        } 
       } 

       //Close the stream 
       in.close(); 
      } 
      catch (Exception e) 
      { 
       e.printStackTrace(); 
       ok = false; 
      } 

      return (ok); 
     } 
관련 문제