我怎样才能获得存储卡信息?

时间:2015-03-15 05:25:14

标签: android

我正在开发一个Android媒体播放器来播放存储卡中的歌曲。但是我需要正确检测存储卡(可移动媒体)。我可以获得有关插入的介质的信息 - 类型,制造商等吗?

1 个答案:

答案 0 :(得分:0)

if (isExteranlStorageAvailable()) {
        try {
            File input = new File("/sys/class/mmc_host/mmc1");
            String cid_directory = null;
            int i = 0;
            File[] sid = input.listFiles();

            for (i = 0; i < sid.length; i++) {
                if (sid[i].toString().contains("mmc1:")) {
                    cid_directory = sid[i].toString();
                    String SID = (String) sid[i].toString().subSequence(cid_directory.length() - 4,cid_directory.length());
                    Log.d(TAG, " SID of MMC = " + SID);
                    break;
                }
            }
            BufferedReader CID = new BufferedReader(new FileReader(cid_directory + "/cid"));
            String sd_cid = CID.readLine();
            Log.d(TAG, "CID of the MMC = " + sd_cid);
            tv.setText("CID of the MMC = " + sd_cid);

        } catch (Exception e) {
            Log.e("CID_APP", "Can not read SD-card cid");
        }

    } else {
        Toast.makeText(this, "External Storage Not available!!",Toast.LENGTH_SHORT).show();
    }

}

private boolean isExteranlStorageAvailable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}

这给了我写作方式。