Compartilhar via


StorageManager.GetAllocatableBytes(UUID) Method

Definition

Return the maximum number of new bytes that your app can allocate for itself on the given storage volume.

[Android.Runtime.Register("getAllocatableBytes", "(Ljava/util/UUID;)J", "GetGetAllocatableBytes_Ljava_util_UUID_Handler", ApiSince=26)]
public virtual long GetAllocatableBytes (Java.Util.UUID storageUuid);
[<Android.Runtime.Register("getAllocatableBytes", "(Ljava/util/UUID;)J", "GetGetAllocatableBytes_Ljava_util_UUID_Handler", ApiSince=26)>]
abstract member GetAllocatableBytes : Java.Util.UUID -> int64
override this.GetAllocatableBytes : Java.Util.UUID -> int64

Parameters

storageUuid
UUID

the UUID of the storage volume where you're considering allocating disk space, since allocatable space can vary widely depending on the underlying storage device. The UUID for a specific path can be obtained using #getUuidForPath(File).

Returns

the maximum number of new bytes that the calling app can allocate using #allocateBytes(UUID, long) or #allocateBytes(FileDescriptor, long).

Attributes

Remarks

Return the maximum number of new bytes that your app can allocate for itself on the given storage volume. This value is typically larger than File#getUsableSpace(), since the system may be willing to delete cached files to satisfy an allocation request. You can then allocate space for yourself using #allocateBytes(UUID, long) or #allocateBytes(FileDescriptor, long).

This method is best used as a pre-flight check, such as deciding if there is enough space to store an entire music album before you allocate space for each audio file in the album. Attempts to allocate disk space beyond the returned value will fail.

If the returned value is not large enough for the data you'd like to persist, you can launch #ACTION_MANAGE_STORAGE with the #EXTRA_UUID and #EXTRA_REQUESTED_BYTES options to help involve the user in freeing up disk space.

If you're progressively allocating an unbounded amount of storage space (such as when recording a video) you should avoid calling this method more than once every 30 seconds. <p class="note"> Note: if your app uses the android:sharedUserId manifest feature, then allocatable space for all packages in your shared UID is tracked together as a single unit.

Java documentation for android.os.storage.StorageManager.getAllocatableBytes(java.util.UUID).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to