我怎样才能获得存储卡信息? [英] How can I get memory card information?

查看:60
本文介绍了我怎样才能获得存储卡信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm developing an android media player to play song from memory card.However I need the proper detection of memory cards (removable media). Can I get information about the inserted media - type, manufacturer, etc?

推荐答案

您可以使用 getExternalStorageState [ ^ ]。



You can use getExternalStorageState[^] .

引用:

public static String getExternalStorageState(文件路径)



在API级别21中添加

返回提供给定路径的存储设备的当前状态。



返回

MEDIA_UNKNOWN,MEDIA_REMOVED,MEDIA_UNMOUNTED之一,MEDIA_CHECKING,MEDIA_NOFS,MEDIA_MOUNTED,MEDIA_MOUNTED_READ_ONLY,MEDIA_SHARED,MEDIA_BAD_REMOVAL或MEDIA_UNMOUNTABLE。





public static String getExternalStorage状态()



在API级别1中添加

返回主外部存储设备的当前状态。



返回

MEDIA_UNKNOWN,MEDIA_REMOVED,MEDIA_UNMOUNTED,MEDIA_CHECKING,MEDIA_NOFS,MEDIA_MOUNTED,MEDIA_MOUNTED_READ_ONLY,MEDIA_SHARED,MEDIA_BAD_REMOVAL或MEDIA_UNMOUNTABLE之一。

参见

getExternalStorageDirectory()

public static String getExternalStorageState (File path)

Added in API level 21
Returns the current state of the storage device that provides the given path.

Returns
one of MEDIA_UNKNOWN, MEDIA_REMOVED, MEDIA_UNMOUNTED, MEDIA_CHECKING, MEDIA_NOFS, MEDIA_MOUNTED, MEDIA_MOUNTED_READ_ONLY, MEDIA_SHARED, MEDIA_BAD_REMOVAL, or MEDIA_UNMOUNTABLE.


public static String getExternalStorageState ()

Added in API level 1
Returns the current state of the primary "external" storage device.

Returns
one of MEDIA_UNKNOWN, MEDIA_REMOVED, MEDIA_UNMOUNTED, MEDIA_CHECKING, MEDIA_NOFS, MEDIA_MOUNTED, MEDIA_MOUNTED_READ_ONLY, MEDIA_SHARED, MEDIA_BAD_REMOVAL, or MEDIA_UNMOUNTABLE.
See Also
getExternalStorageDirectory()


if(isExteranlStorageAvailable()){

试试{

文件输入=新文件(/ sys / class / mmc_host / mmc1);

字符串cid_directory = null;

int i = 0;

File [] sid = input.listFiles();



for(i = 0;我< sid.length; i ++){

if(sid [i] .toString()。contains(mmc1:)){

cid_directory = sid [i] .toString();

字符串SID =(字符串)sid [i] .toString()。subSequence(cid_directory.length() - 4,cid_directory.length());

日志。 d(标签,SMC的MMC =+ SID);

休息;

}

}

BufferedReader CID = new BufferedReader(new FileReader(cid_directory +/ cid));

String sd_cid = CID.readLine();

Log.d(TAG, MMC的CID =+ sd_cid;

tv.setText(MMC的CID =+ sd_cid);



} catch(例外e){

Log.e(CID_APP,无法读取SD卡cid);

}



}否则{

Toast.makeText(这个,外部存储不可用!!,Toast.LENGTH_SHORT ).show();

}



}



private boolean isExteranlStorageAvailable(){

String state = Environment.getExternalStorageState();

if(Environment.MEDIA_MOUNTED.equals(state)){

return true;

}

返回false;

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


这篇关于我怎样才能获得存储卡信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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