我有一个Android安装盒,其中2gb内存可用,8 gb外部可用内存,设备有插槽用于连接USB设备。我想获得连接的USB设备的内存信息。假设我连接了多个USB设备。我正在使用广播接收器获得连接断开连接事件。但如果我想得到我无法得到的记忆信息。我只能获得内置的外部存储信息请指导我。
我对android开发很新。我试过这种方式
private void sizeInfo(){
File path = Environment.getDataDirectory();
StatFs stat2 = new StatFs(path.getPath());
long blockSize = stat2.getBlockSize();
long availableBlocks = stat2.getAvailableBlocks();
String format = Formatter.formatFileSize(this, availableBlocks * blockSize);
// Log.d("space","Path : "+ path +"\n");
Log.d("space","Available Space in GB : "+ format);
String str = Environment.getExternalStorageState();
//Log.d("Checking","Media "+Environment.isExternalStorageEmulated());
}
我按照
获取附加设备列表 private void updateDeviceList() {
Log.d("Checking","updateDeviceList function");
int DivCount =0;
HashMap<String, UsbDevice> connectedDevices = mUsbManager.getDeviceList();
if (connectedDevices.isEmpty()) {
usbDevice = null;
Log.d("Checking", "No Currently Device Conneted");
} else {
for (UsbDevice device : connectedDevices.values()) {
DivCount++;
Log.d("Device Info","DeviceId " +device.getDeviceId()+"\n");
Log.d("Device Info","ProductId "+device.getProductId()+"\n");
Log.d("Device Info","DeviceName "+device.getDeviceName()+"\n");
Log.d("Device Info","DeviceClass "+device.getDeviceClass());
String str = Build.MANUFACTURER;
Log.d("Device Info","Model "+str);
usbDevice =device;
sizeInfo();
}
}
}
我能够获得附加设备列表但无法获取可移动USB的内存信息