Example usage for android.content Intent ACTION_MEDIA_EJECT

List of usage examples for android.content Intent ACTION_MEDIA_EJECT

Introduction

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

Prototype

String ACTION_MEDIA_EJECT

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

Click Source Link

Document

Broadcast Action: User has expressed the desire to remove the external storage media.

Usage

From source file:org.videolan.vlc.gui.tv.browser.BaseTvActivity.java

@Override
protected void onResume() {
    super.onResume();
    mIsVisible = true;//  w  w  w  .j  a va2  s  .com
    //Handle network connection state
    IntentFilter networkFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);

    IntentFilter storageFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED);
    storageFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
    storageFilter.addAction(Intent.ACTION_MEDIA_EJECT);
    storageFilter.addDataScheme("file");
    IntentFilter parsingServiceFilter = new IntentFilter(MediaParsingService.ACTION_SERVICE_ENDED);
    parsingServiceFilter.addAction(MediaParsingService.ACTION_SERVICE_STARTED);

    mRegistering = true;
    LocalBroadcastManager.getInstance(this).registerReceiver(mParsingServiceReceiver, parsingServiceFilter);
    registerReceiver(mExternalDevicesReceiver, storageFilter);
    registerReceiver(mExternalDevicesReceiver, networkFilter);
}

From source file:org.videolan.vlc.gui.DirectoryViewFragment.java

@Override
public void onStart() {
    super.onStart();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_REMOVED);
    filter.addAction(Intent.ACTION_MEDIA_EJECT);
    filter.addDataScheme("file");
    getActivity().registerReceiver(messageReceiver, filter);
}

From source file:com.loloof64.android.chess_position_manager.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MEDIA_REMOVED);
    filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
    filter.addAction(Intent.ACTION_MEDIA_EJECT);
    filter.addAction(Intent.ACTION_MEDIA_NOFS);
    filter.addAction(Intent.ACTION_MEDIA_SHARED);
    filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    registerReceiver(mStorageReceiver, filter);
}

From source file:com.mine.psf.PsfPlaybackService.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  av a  2 s  .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)) {
                    Log.d(LOGTAG, "SD Card Ejected, stop...");
                    saveQueue();
                    stop();
                    notifyChange(META_CHANGED);
                } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                    reloadQueue();
                    notifyChange(META_CHANGED);
                    Log.d(LOGTAG, "SD Card Mounted...");
                }
            }
        };
        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.koma.music.service.MusicService.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. java  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(MusicServiceConstants.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.av.remusic.service.MediaService.java

public void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override//w  w  w .j  ava  2 s.  c om
            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();
                    reloadQueueAfterPermissionCheck();
                    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:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.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 . java  2  s  .c om
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(MediaPlaybackService.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("file");
        registerReceiver(mUnmountReceiver, iFilter);
    }
}

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./*from   w w  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./*w ww  .  ja va  2 s  . c o m*/
 */
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./*  ww  w .ja  va2s  . c om*/
 */
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);
    }
}