0

我有一个 android 设置盒,其中有 2gb 内部存储器和 8gb 外部存储器可用,并且设备有用于连接 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 的内存信息

4

0 回答 0