Я использую библиотеку Libaums в своем приложении для Android, но не могу понять, как ее использовать.Ниже приведен фрагмент кода, который я пробовал:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Configuration config = getResources().getConfiguration();
if (config.smallestScreenWidthDp >= 600) {
setContentView(activity_mainplay);
} else {
setContentView(activity_mainplay);
}
final Context ctx = getApplicationContext();
UsbMassStorageDevice[] devices = UsbMassStorageDevice.getMassStorageDevices(ctx);
for (UsbMassStorageDevice device : devices) {
// before interacting with a device you need to call init()!
String actionString = ctx.getPackageName() + ".action.USB_PERMISSION";
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(ctx, 0, new
Intent(actionString), 0);
UsbManager manager = (UsbManager) newjava.this.getSystemService(ctx.USB_SERVICE);
// device.init();
// Only uses the first partition on the device
FileSystem currentFs = device.getPartitions().get(0).getFileSystem();
Toast.makeText(newjava.this, "chunk size=="+currentFs.getChunkSize(), 1000).show();
Toast.makeText(newjava.this, "occ size=="+currentFs.getOccupiedSpace(), 1000).show();
Log.d(TAG, "Capacity: " + currentFs.getCapacity());
Log.d(TAG, "Occupied Space: " + currentFs.getOccupiedSpace());
Log.d(TAG, "Free Space: " + currentFs.getFreeSpace());
Log.d(TAG, "Chunk size: " + currentFs.getChunkSize());
}
}
Код перестает выполняться при доступе к разрешениям USB.Кто-нибудь может предоставить рабочий код или указать, где я ошибаюсь?