Example usage for android.content Intent ACTION_MEDIA_MOUNTED

List of usage examples for android.content Intent ACTION_MEDIA_MOUNTED

Introduction

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

Prototype

String ACTION_MEDIA_MOUNTED

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

Click Source Link

Document

Broadcast Action: External media is present and mounted at its mount point.

Usage

From source file:com.cyanogenmod.eleven.MusicPlaybackService.java

/**
 * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The
 * intent will call closeExternalStorageFiles() if the external media is
 * going to be ejected, so applications can clean up any files they have
 * open.//  ww  w.j a  v a  2 s .c  o m
 */
public void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void onReceive(final Context context, final Intent intent) {
                final String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                    saveQueue(true);
                    mQueueIsSaveable = false;
                    closeExternalStorageFiles(intent.getData().getPath());
                } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                    mMediaMountedCount++;
                    mCardId = getCardId();
                    reloadQueue();
                    mQueueIsSaveable = true;
                    notifyChange(QUEUE_CHANGED);
                    notifyChange(META_CHANGED);
                }
            }
        };
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_EJECT);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addDataScheme("file");
        registerReceiver(mUnmountReceiver, filter);
    }
}

From source file:com.andrew.apollo.MusicPlaybackService.java

/**
 * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The
 * intent will call closeExternalStorageFiles() if the external media is
 * going to be ejected, so applications can clean up any files they have
 * open.//from  w  w w .  jav  a2  s . com
 */
private void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void onReceive(final Context context, final Intent intent) {
                final String action = intent.getAction();
                if (action != null) {
                    if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                        saveQueue(true);
                        mQueueIsSaveable = false;
                        closeExternalStorageFiles();
                    } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                        mMediaMountedCount++;
                        mCardId = getCardId();
                        reloadQueue();
                        mQueueIsSaveable = true;
                        notifyChange(QUEUE_CHANGED);
                        notifyChange(META_CHANGED);
                    }
                }
            }
        };
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_EJECT);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addDataScheme("file");
        registerReceiver(mUnmountReceiver, filter);
    }
}

From source file:com.andrew.apolloMod.service.ApolloService.java

/**
 * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The
 * intent will call closeExternalStorageFiles() if the external media is
 * going to be ejected, so applications can clean up any files they have
 * open.//from  w w w .j  av a  2s. com
 */
public void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                    saveQueue(true);
                    mQueueIsSaveable = false;
                    closeExternalStorageFiles(intent.getData().getPath());
                } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                    mMediaMountedCount++;
                    mCardId = MusicUtils.getCardId(ApolloService.this);
                    reloadQueue();
                    mQueueIsSaveable = true;
                    notifyChange(QUEUE_CHANGED);
                    notifyChange(META_CHANGED);
                }
            }
        };
        IntentFilter iFilter = new IntentFilter();
        iFilter.addAction(Intent.ACTION_MEDIA_EJECT);
        iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        iFilter.addDataScheme(DATA_SCHEME);
        registerReceiver(mUnmountReceiver, iFilter);
    }
}

From source file:org.mariotaku.harmony.MusicPlaybackService.java

/**
 * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The
 * intent will call closeExternalStorageFiles() if the external media is
 * going to be ejected, so applications can clean up any files they have
 * open./*from   w  w  w  .  j a va2s. c o m*/
 */
public void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {

                String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                    saveQueue(true);
                    mQueueIsSaveable = false;
                    closeExternalStorageFiles(intent.getData().getPath());
                } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                    mCardId = MusicUtils.getCardId(context);
                    reloadQueue();
                    mQueueIsSaveable = true;
                    notifyChange(BROADCAST_QUEUE_CHANGED);
                    notifyChange(BROADCAST_MEDIA_CHANGED);
                }
            }
        };
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_EJECT);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addDataScheme(ContentResolver.SCHEME_FILE);
        registerReceiver(mUnmountReceiver, filter);
    }
}

From source file:com.android.server.MountService.java

private void notifyVolumeStateChange(String label, String path, int oldState, int newState) {
    final StorageVolume volume;
    final String state;
    synchronized (mVolumesLock) {
        volume = mVolumesByPath.get(path);
        state = getVolumeState(path);// ww  w.  j  a v  a2 s . c  o  m
    }

    if (DEBUG_EVENTS)
        Slog.i(TAG, "notifyVolumeStateChange::" + state);

    String action = null;

    if (oldState == VolumeState.Shared && newState != oldState) {
        if (LOCAL_LOGD)
            Slog.d(TAG, "Sending ACTION_MEDIA_UNSHARED intent");
        sendStorageIntent(Intent.ACTION_MEDIA_UNSHARED, volume, UserHandle.ALL);
    }

    if (newState == VolumeState.Init) {
    } else if (newState == VolumeState.NoMedia) {
        // NoMedia is handled via Disk Remove events
    } else if (newState == VolumeState.Idle) {
        /*
         * Don't notify if we're in BAD_REMOVAL, NOFS, UNMOUNTABLE, or
         * if we're in the process of enabling UMS
         */
        if (!state.equals(Environment.MEDIA_BAD_REMOVAL) && !state.equals(Environment.MEDIA_NOFS)
                && !state.equals(Environment.MEDIA_UNMOUNTABLE) && !getUmsEnabling()) {
            if (DEBUG_EVENTS)
                Slog.i(TAG, "updating volume state for media bad removal nofs and unmountable");
            updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
            action = Intent.ACTION_MEDIA_UNMOUNTED;
        }
    } else if (newState == VolumeState.Pending) {
    } else if (newState == VolumeState.Checking) {
        if (DEBUG_EVENTS)
            Slog.i(TAG, "updating volume state checking");
        updatePublicVolumeState(volume, Environment.MEDIA_CHECKING);
        action = Intent.ACTION_MEDIA_CHECKING;
    } else if (newState == VolumeState.Mounted) {
        if (DEBUG_EVENTS)
            Slog.i(TAG, "updating volume state mounted");
        updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
        action = Intent.ACTION_MEDIA_MOUNTED;
    } else if (newState == VolumeState.Unmounting) {
        action = Intent.ACTION_MEDIA_EJECT;
    } else if (newState == VolumeState.Formatting) {
    } else if (newState == VolumeState.Shared) {
        if (DEBUG_EVENTS)
            Slog.i(TAG, "Updating volume state media mounted");
        /* Send the media unmounted event first */
        updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
        sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);

        if (DEBUG_EVENTS)
            Slog.i(TAG, "Updating media shared");
        updatePublicVolumeState(volume, Environment.MEDIA_SHARED);
        action = Intent.ACTION_MEDIA_SHARED;
        if (LOCAL_LOGD)
            Slog.d(TAG, "Sending ACTION_MEDIA_SHARED intent");
    } else if (newState == VolumeState.SharedMnt) {
        Slog.e(TAG, "Live shared mounts not supported yet!");
        return;
    } else {
        Slog.e(TAG, "Unhandled VolumeState {" + newState + "}");
    }

    if (action != null) {
        sendStorageIntent(action, volume, UserHandle.ALL);
    }
}

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

@Override
public void onResume() {
    super.onResume();
    if (materialDialog != null && !materialDialog.isShowing()) {
        materialDialog.show();//from w w w. java 2 s  . c  o  m
        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("general_communications"));
    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);
    }
}

From source file:com.filemanager.free.activities.MainActivity.java

@Override
public void onResume() {
    AdWrapper.viewAd(true, mainActivity);
    requestNewInterstitial();//  w ww  .j a  va 2 s .c o  m
    if (materialDialog != null && !materialDialog.isShowing()) {
        materialDialog.show();
        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("general_communications"));
    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);
    }
    super.onResume();
}

From source file:com.igniva.filemanager.activities.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    if (materialDialog != null && !materialDialog.isShowing()) {
        materialDialog.show();/*from w  ww. j a va  2 s . c  o m*/
        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("general_communications"));
    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);
    }

    // Registering intent filter for OTG
    IntentFilter otgFilter = new IntentFilter();
    otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
}

From source file:org.yammp.MusicPlaybackService.java

/**
 * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The
 * intent will call closeExternalStorageFiles() if the external media is
 * going to be ejected, so applications can clean up any files they have
 * open./* w w w  .j a v  a2 s  . co  m*/
 */
public void registerExternalStorageListener() {

    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {

                String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                    saveQueue(true);
                    mQueueIsSaveable = false;
                    closeExternalStorageFiles(intent.getData().getPath());
                } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                    mMediaMountedCount++;
                    mCardId = mUtils.getCardId();
                    reloadQueue();
                    mQueueIsSaveable = true;
                    notifyChange(BROADCAST_QUEUE_CHANGED);
                    notifyChange(BROADCAST_META_CHANGED);
                }
            }
        };
        IntentFilter iFilter = new IntentFilter();
        iFilter.addAction(Intent.ACTION_MEDIA_EJECT);
        iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        iFilter.addDataScheme("file");
        registerReceiver(mUnmountReceiver, iFilter);
    }
}

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

@Override
public void onResume() {
    super.onResume();
    if (materialDialog != null && !materialDialog.isShowing()) {
        materialDialog.show();//ww w .ja  va2s .  c  o m
        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);
        }
    }
}