Example usage for android.os.storage StorageManager findVolumeById

List of usage examples for android.os.storage StorageManager findVolumeById

Introduction

In this page you can find the example usage for android.os.storage StorageManager findVolumeById.

Prototype

@UnsupportedAppUsage
public @Nullable VolumeInfo findVolumeById(String id) 

Source Link

Usage

From source file:com.android.tv.settings.device.storage.UnmountActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mUnmountVolumeId = getIntent().getStringExtra(VolumeInfo.EXTRA_VOLUME_ID);
    mUnmountVolumeDesc = getIntent().getStringExtra(EXTRA_VOLUME_DESC);

    LocalBroadcastManager.getInstance(this).registerReceiver(mUnmountReceiver,
            new IntentFilter(SettingsStorageService.ACTION_UNMOUNT));

    if (savedInstanceState == null) {
        final StorageManager storageManager = getSystemService(StorageManager.class);
        final VolumeInfo volumeInfo = storageManager.findVolumeById(mUnmountVolumeId);

        if (volumeInfo == null) {
            // Unmounted already, just bail
            finish();//from   w  w  w . j  a  va2s .  c o m
            return;
        }

        if (volumeInfo.getType() == VolumeInfo.TYPE_PRIVATE) {
            final Fragment fragment = UnmountPrivateStepFragment.newInstance(mUnmountVolumeId);
            getFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
        } else {
            // Jump straight to unmounting
            onRequestUnmount();
        }
    }
}