2013-05-21 2 views

Répondre

2

Utilisez cette option pour obtenir l'autre sdcard externe:

File storageDir= new File("/mnt/external_sd/") 

OU

File storageDir= new File("/mnt/extSdCard/") 

Pour plus de détails, voir http://mono-for-android.1047100.n5.nabble.com/detect-SD-Card-path-td5710218.html#a5710250 et this

Alors que, comme cela utiliser une fonction pour obtenir la liste des toutes les cartes ext ...

public static HashSet<String> getExternalMounts() { 
    final HashSet<String> out = new HashSet<String>(); 
    String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*"; 
    String s = ""; 
    try { 
     final Process process = new ProcessBuilder().command("mount") 
       .redirectErrorStream(true).start(); 
     process.waitFor(); 
     final InputStream is = process.getInputStream(); 
     final byte[] buffer = new byte[1024]; 
     while (is.read(buffer) != -1) { 
      s = s + new String(buffer); 
     } 
     is.close(); 
    } catch (final Exception e) { 
     e.printStackTrace(); 
    } 

    // parse output 
    final String[] lines = s.split("\n"); 
    for (String line : lines) { 
     if (!line.toLowerCase(Locale.US).contains("asec")) { 
      if (line.matches(reg)) { 
       String[] parts = line.split(" "); 
       for (String part : parts) { 
        if (part.startsWith("/")) 
         if (!part.toLowerCase(Locale.US).contains("vold")) 
          out.add(part); 
       } 
      } 
     } 
    } 
    return out; 
} 
+0

comment puis-je obtenir la chaîne (chemin) par programmaticlly? – RealDream

+0

Chemin de chaîne = storageDir.getAbsolutePath(); –

+2

Hardcoding chemin sdcard n'est pas une bonne idée, il peut être différent sur différents périphériques – pedja

Questions connexes