2

Is there any way of identifying if there are two sd-cards in a device??

Edit:

I have found that at the moment, there is no way of distinguishing between internal storage and true external SD card. In some devices like Samsung Galaxy Tab (7 inches), the system takes the internal storage (usually 16gb) to be as an external storage. Unfortunately there is no way to distinguish between internal storage and secondar/external/sd-card storage. If someone thinks it is possible (for honeycomb and previous versions), write here and I'll prove it.

Compass
  • 5,867
  • 4
  • 30
  • 42
Farhan
  • 3,206
  • 14
  • 49
  • 62

2 Answers2

1

I don't believe there is a way to check for dual sd-cards, but some devices do have 2 types of external storage. For example, I know on some motorola devices, the internal secondary storage is accessed with /sdcard-ext. You could check to see if this directory exists (I know that other devices with secondary storage also use the -ext append) and react accordingly.

John Leehey
  • 22,052
  • 8
  • 61
  • 88
  • yes, you are right.There are certain devices which consider internal storage as sd-card. Can you just elaborate how can I differentiate between an internal storage that is treated as an sd-card and an actual external sd-card.. – Farhan Aug 12 '11 at 18:54
  • 1
    Take a look at `Environment.isExternalStorageEmulated()` and `Environment.isExternalStorageRemovable()` - see http://developer.android.com/reference/android/os/Environment.html –  Aug 12 '11 at 18:56
0

There are devices that have both an emulated and a physical SD. (eg Sony Xperia Z). It won't expose the physical SD card because methods like getExternalFilesDir(null) will return the emulated SD card. I use the following code to get the directory for the physical SD. The call returns all mountpoints and the online SD cards. You will have to figure out which mountpoint refers to a OFFLINE SD card (if any), but most of the time you are only interested in ONLINE SD cards.

        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);
        }
user1536307
  • 81
  • 1
  • 2