如何读取 SD 卡 ID 号? [英] How to read the SD Card ID number?

查看:38
本文介绍了如何读取 SD 卡 ID 号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式读取 SD 卡的 CID 寄存器,其中包含序列号和其他信息?我可以通过 Android Java 或 Native 代码来实现吗?

How can I programatically read the SD Card's CID register, which contains a Serial Number and other information? Can I do it through Android Java, or Native code?

提前致谢,埃里克

推荐答案

这里是获取SID和CID的示例代码

Here is sample code for getting SID and CID

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);

    } 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();
}

这篇关于如何读取 SD 卡 ID 号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆