How to get android system path and space external sd card usage? ? getExternalStorageDirectory way to get just the built-in sd card information. Or how to get through jni c it? Space usage external sd card how to get it<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
/ *** Get free sd card space size * @ return * /
public long getAvailaleSize () {File path = Environment.getExternalStorageDirectory (); / / get the file path sdcard StatFs stat = new StatFs (path.getPath ()); / * Get block of SIZE * / long blockSize = stat.getBlockSize (); / * number of idle Block * / long availableBlocks = stat.getAvailableBlocks (); / * Returns bit size value * / return availableBlocks * blockSize; / / (availableBlocks * blockSize) / 1024 KIB unit / / (availableBlocks * blockSize) / 1024/1024 MIB Unit}
Reply:
public long getAvailaleSize () {File path = Environment.getExternalStorageDirectory (); / / get sdcard file path StatFs stat = new StatFs (path.getPath ()); / * Get block of SIZE * / long blockSize = stat.getBlockSize (); / * number of idle Block * / long availableBlocks = stat.getAvailableBlocks (); / * Return bit size value * / return availableBlocks * blockSize; / / (availableBlocks * blockSize) / 1024 KIB units / / (availableBlocks * blockSize) / 1024/1024 MIB Unit} Reply:
public long getAvailaleSize () {
File path = Environment.getExternalStorageDirectory (); / / get the file path
sdcardStatFs stat = new StatFs (path.getPath ());
/ * Get block of SIZE * /
long blockSize = stat.getBlockSize ();
/ * Number of idle Block * /
long availableBlocks = stat.getAvailableBlocks ();
/ * Return bit size value * /
return availableBlocks * blockSize;
/ / (AvailableBlocks * blockSize) / 1024 KIB unit
/ / (AvailableBlocks * blockSize) / 1024/1024 MIB unit}
Reply:
Obtained in this way is still the built-sd card path, but how to get it externally? I assume that the pad can insert two sd card how to do?
Reply:
The following is the method I have found, the path of all storage devices on which you can get android, is that all, including usbotg so on. Is there any way to distinguish which is the external sd card do? ?
StorageManager sm = (StorageManager) MainActivity.this.getSystemService (Context.STORAGE_SERVICE);
/ / Get the path sdcard: external and internal
try {
paths = (String []) sm.getClass () getMethod ("getVolumePaths", null) invoke (sm, null);..
} Catch (IllegalArgumentException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
} Catch (IllegalAccessException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
} Catch (InvocationTargetException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
} Catch (NoSuchMethodException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
No comments:
Post a Comment