Example usage for android.content Intent ACTION_MEDIA_UNMOUNTED

List of usage examples for android.content Intent ACTION_MEDIA_UNMOUNTED

Introduction

In this page you can find the example usage for android.content Intent ACTION_MEDIA_UNMOUNTED.

Prototype

String ACTION_MEDIA_UNMOUNTED

To view the source code for android.content Intent ACTION_MEDIA_UNMOUNTED.

Click Source Link

Document

Broadcast Action: External media is present, but not mounted at its mount point.

Usage

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    if (materialDialog != null && !materialDialog.isShowing()) {
        materialDialog.show();/*from  www  .  ja va  2  s  . c  om*/
        materialDialog = null;
    }

    IntentFilter newFilter = new IntentFilter();
    newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    newFilter.addDataScheme(ContentResolver.SCHEME_FILE);
    registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter);
    registerReceiver(receiver2, new IntentFilter(TAG_INTENT_FILTER_GENERAL));
    if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName()
            .contains("TabFragment")) {

        floatingActionButton.setVisibility(View.VISIBLE);
        floatingActionButton.showMenuButton(false);
    } else {

        floatingActionButton.setVisibility(View.INVISIBLE);
        floatingActionButton.hideMenuButton(false);
    }

    if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // Registering intent filter for OTG
        IntentFilter otgFilter = new IntentFilter();
        otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
        otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
        registerReceiver(mOtgReceiver, otgFilter);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // let's register encryption service to know when we've decrypted
        Intent encryptIntent = new Intent(this, EncryptService.class);
        bindService(encryptIntent, mEncryptServiceConnection, 0);

        if (!isEncryptOpen && encryptBaseFile != null) {
            // we've opened the file and are ready to delete it
            // don't move this to ondestroy as we'll be getting destroyed and starting
            // an async task just before it is not a good idea
            ArrayList<BaseFile> baseFiles = new ArrayList<>();
            baseFiles.add(encryptBaseFile);
            new DeleteTask(getContentResolver(), this).execute(baseFiles);
        }
    }
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

public void handleMediaReceiver() {
    storageReceiver = new BroadcastReceiver() {
        @Override/* ww w  .  jav  a2  s . c om*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            String data = intent.getDataString();
            final String path = data.replace("file://", "");
            if (action.equals(Intent.ACTION_MEDIA_MOUNTED))
                handleRefreshMedia(path, true, 10);
            else
                refreshBookmarks();
        }
    };

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    filter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    filter.addAction(Intent.ACTION_MEDIA_EJECT);
    filter.addDataScheme("file");
    registerReceiver(storageReceiver, filter);

    ContentObserver mDbObserver = new ContentObserver(mHandler) {
        @Override
        public void onChange(boolean selfChange) {
            //rebake(false, ImageManager.isMediaScannerScanning(
            //      getContentResolver()));
        }
    };

    getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true,
            mDbObserver);
}