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:org.chromium.ChromeSystemStorage.java

private static BackgroundEventHandler<ChromeSystemStorage> createEventHandler() {

    return new BackgroundEventHandler<ChromeSystemStorage>() {

        @Override/*from ww  w.  j ava2  s.c o  m*/
        public BackgroundEventInfo mapBroadcast(Context context, Intent intent) {

            String action = intent.getAction();
            if (!(Intent.ACTION_MEDIA_MOUNTED.equals(action) || Intent.ACTION_MEDIA_BAD_REMOVAL.equals(action)
                    || Intent.ACTION_MEDIA_REMOVED.equals(action) || Intent.ACTION_MEDIA_SHARED.equals(action)
                    || Intent.ACTION_MEDIA_UNMOUNTED.equals(action))) {
                // Ignore any other actions
                return null;
            }

            BackgroundEventInfo event = new BackgroundEventInfo(action);
            event.getData().putString(DATA_STORAGE_PATH, intent.getDataString());

            return event;
        }

        @Override
        public void mapEventToMessage(BackgroundEventInfo event, JSONObject message) throws JSONException {
            boolean attached = Intent.ACTION_MEDIA_MOUNTED.equals(event.action);

            // Sanitize the path provided with the event
            String storagePath = getBaseStoragePath(
                    Uri.parse(event.getData().getString(DATA_STORAGE_PATH)).getPath());

            ChromeSystemStorage plugin = getCurrentPlugin();

            // The attached/detached events may fire before the client has a chance to call getInfo().
            // Thus, must initialize the external storage here (if not already done), to ensure that
            // unit ids are consistent across calls to getInfo, and subsequent attach/detach events.
            StorageFile[] directories = plugin.initializeExternalStorageDirectories();

            String unitId = plugin.getExternalStorageId(storagePath);
            StorageFile attachedStorage = null;
            if (attached) {
                attachedStorage = plugin.getExternalStorageDirectoryByPath(storagePath, directories);
            } else {
                // If the detached event causes initialization, the unit id may not be found
                // as it won't be reported in the list of directories.  We can safely generate
                // a random id, as the client won't have called getInfo yet.
                if (unitId == null) {
                    unitId = UUID.randomUUID().toString();
                }
            }

            message.put("action", attached ? "attached" : "detached");
            message.put("id", unitId);
            if (attached) {
                JSONObject storageUnit = plugin.buildExternalStorageUnitInfo(attachedStorage);

                message.put("info", storageUnit);
            }
        }
    };
}

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.android.music.ArtistAlbumBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View view = inflater.inflate(R.layout.media_picker_activity_expanding, null);
    getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(getActivity(), this);

    if (savedInstanceState != null) {
        mCurrentAlbumId = savedInstanceState.getString("selectedalbum");
        mCurrentAlbumName = savedInstanceState.getString("selectedalbumname");
        mCurrentArtistId = savedInstanceState.getString("selectedartist");
        mCurrentArtistName = savedInstanceState.getString("selectedartistname");
    }//from ww w.  j a v  a  2  s . c  o m

    IntentFilter f = new IntentFilter();
    f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    f.addDataScheme("file");
    getActivity().registerReceiver(mScanListener, f);

    lv = (ExpandableListView) view.findViewById(android.R.id.list);

    mAdapter = (ArtistAlbumListAdapter) getActivity().getLastNonConfigurationInstance();
    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new ArtistAlbumListAdapter(getActivity().getApplication(), this, null, // cursor
                R.layout.track_list_item_group, new String[] {}, new int[] {}, R.layout.track_list_item_child,
                new String[] {}, new int[] {});
        lv.setAdapter(mAdapter);
        getArtistCursor(mAdapter.getQueryHandler(), null);
    } else {
        mAdapter.setActivity(this);
        lv.setAdapter(mAdapter);
        mArtistCursor = mAdapter.getCursor();
        if (mArtistCursor != null) {
            init(mArtistCursor);
        } else {
            getArtistCursor(mAdapter.getQueryHandler(), null);
        }
    }

    lv.setOnCreateContextMenuListener(this);
    lv.setOnChildClickListener(this);
    lv.setTextFilterEnabled(true);

    return view;
}

From source file:com.android.music.AlbumBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View view = inflater.inflate(R.layout.media_picker_activity, null);

    if (savedInstanceState != null) {
        mCurrentAlbumId = savedInstanceState.getString("selectedalbum");
        mArtistId = savedInstanceState.getString("artist");
    } else {//ww w  .  j  a  v  a  2 s.  co m
        mArtistId = getActivity().getIntent().getStringExtra("artist");
    }

    //getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(getActivity(), this);

    IntentFilter f = new IntentFilter();
    f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    f.addDataScheme("file");
    getActivity().registerReceiver(mScanListener, f);

    lv = (ListView) view.findViewById(android.R.id.list);
    lv.setOnCreateContextMenuListener(this);
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(this);

    mAdapter = (AlbumListAdapter) getActivity().getLastNonConfigurationInstance();
    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new AlbumListAdapter(getActivity().getApplication(), this, R.layout.track_list_item,
                mAlbumCursor, new String[] {}, new int[] {});
        lv.setAdapter(mAdapter);
        //getActivity().setTitle(R.string.working_albums);
        getAlbumCursor(mAdapter.getQueryHandler(), null);
    } else {
        mAdapter.setActivity(this);
        lv.setAdapter(mAdapter);
        mAlbumCursor = mAdapter.getCursor();
        if (mAlbumCursor != null) {
            init(mAlbumCursor);
        } else {
            getAlbumCursor(mAdapter.getQueryHandler(), null);
        }
    }

    return view;
}

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

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

    //Handle external storage state
    IntentFilter storageFilter = new IntentFilter();
    storageFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    storageFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    storageFilter.addDataScheme("file");
    registerReceiver(storageReceiver, storageFilter);

    /* Prepare the progressBar */
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_SHOW_PLAYER);
    registerReceiver(messageReceiver, filter);
    mClient.connect();/*from   w  w  w. jav a 2 s  . c  o m*/
}

From source file:com.android.music.AlbumBrowserActivity.java

/** Called when the activity is first created. */
@Override/*from  w ww .j  a  va2s  . c  o m*/
public void onCreate(Bundle icicle) {
    if (icicle != null) {
        mCurrentAlbumId = icicle.getString("selectedalbum");
        mArtistId = icicle.getString("artist");
    } else {
        mArtistId = getIntent().getStringExtra("artist");
    }
    super.onCreate(icicle);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(this, this);

    IntentFilter f = new IntentFilter();
    f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    f.addDataScheme("file");
    registerReceiver(mScanListener, f);

    setContentView(R.layout.media_picker_activity);
    MusicUtils.updateButtonBar(this, R.id.albumtab);
    ListView lv = getListView();
    lv.setOnCreateContextMenuListener(this);
    lv.setTextFilterEnabled(true);

    mAdapter = (AlbumListAdapter) getLastNonConfigurationInstance();
    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new AlbumListAdapter(getApplication(), this, R.layout.track_list_item, mAlbumCursor,
                new String[] {}, new int[] {});
        setListAdapter(mAdapter);
        setTitle(R.string.working_albums);
        getAlbumCursor(mAdapter.getQueryHandler(), null);
    } else {
        mAdapter.setActivity(this);
        setListAdapter(mAdapter);
        mAlbumCursor = mAdapter.getCursor();
        if (mAlbumCursor != null) {
            init(mAlbumCursor);
        } else {
            getAlbumCursor(mAdapter.getQueryHandler(), null);
        }
    }

    badSymptoms = new BadSymptoms(this);
}

From source file:com.android.music.PlaylistBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View view = inflater.inflate(R.layout.media_picker_activity, null);

    final Intent intent = getActivity().getIntent();
    final String action = intent.getAction();
    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        mCreateShortcut = true;//from  w ww .j  a  va 2  s  .co m
    }

    getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(getActivity(), new ServiceConnection() {
        public void onServiceConnected(ComponentName classname, IBinder obj) {
            if (Intent.ACTION_VIEW.equals(action)) {
                Bundle b = intent.getExtras();
                if (b == null) {
                    Log.w(TAG, "Unexpected:getExtras() returns null.");
                } else {
                    try {
                        long id = Long.parseLong(b.getString("playlist"));
                        if (id == RECENTLY_ADDED_PLAYLIST) {
                            playRecentlyAdded();
                        } else if (id == PODCASTS_PLAYLIST) {
                            playPodcasts();
                        } else if (id == ALL_SONGS_PLAYLIST) {
                            long[] list = MusicUtils.getAllSongs(getActivity());
                            if (list != null) {
                                MusicUtils.playAll(getActivity(), list, 0);
                            }
                        } else {
                            MusicUtils.playPlaylist(getActivity(), id);
                        }
                    } catch (NumberFormatException e) {
                        Log.w(TAG, "Playlist id missing or broken");
                    }
                }
                getActivity().finish();
                return;
            }
            MusicUtils.updateNowPlaying(getActivity());
        }

        public void onServiceDisconnected(ComponentName classname) {
        }

    });

    IntentFilter f = new IntentFilter();
    f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    f.addDataScheme("file");
    getActivity().registerReceiver(mScanListener, f);

    lv = (ListView) view.findViewById(android.R.id.list);
    lv.setOnCreateContextMenuListener(this);
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            if (mCreateShortcut) {
                final Intent shortcut = new Intent();
                shortcut.setAction(Intent.ACTION_VIEW);
                shortcut.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/playlist");
                shortcut.putExtra("playlist", String.valueOf(id));

                final Intent intent = new Intent();
                intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
                intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                        ((TextView) view.findViewById(R.id.line1)).getText());
                intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource
                        .fromContext(getActivity(), R.drawable.ic_launcher_shortcut_music_playlist));

                getActivity().setResult(getActivity().RESULT_OK, intent);
                getActivity().finish();
                return;
            }
            if (id == RECENTLY_ADDED_PLAYLIST) {
                Intent intent = new Intent(Intent.ACTION_PICK);
                intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
                intent.putExtra("playlist", "recentlyadded");
                startActivity(intent);
            } else if (id == PODCASTS_PLAYLIST) {
                Intent intent = new Intent(Intent.ACTION_PICK);
                intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
                intent.putExtra("playlist", "podcasts");
                startActivity(intent);
            } else {
                Intent intent = new Intent(Intent.ACTION_EDIT);
                intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
                intent.putExtra("playlist", Long.valueOf(id).toString());
                startActivity(intent);
            }

        }
    });

    mAdapter = (PlaylistListAdapter) getActivity().getLastNonConfigurationInstance();
    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new PlaylistListAdapter(getActivity().getApplication(), this, R.layout.track_list_item,
                mPlaylistCursor, new String[] { MediaStore.Audio.Playlists.NAME },
                new int[] { android.R.id.text1 });
        lv.setAdapter(mAdapter);
        //setTitle(R.string.working_playlists);
        getPlaylistCursor(mAdapter.getQueryHandler(), null);
    } else {
        mAdapter.setActivity(this);
        lv.setAdapter(mAdapter);
        mPlaylistCursor = mAdapter.getCursor();
        // If mPlaylistCursor is null, this can be because it doesn't have
        // a cursor yet (because the initial query that sets its cursor
        // is still in progress), or because the query failed.
        // In order to not flash the error dialog at the user for the
        // first case, simply retry the query when the cursor is null.
        // Worst case, we end up doing the same query twice.
        if (mPlaylistCursor != null) {
            init(mPlaylistCursor);
        } else {
            //setTitle(R.string.working_playlists);
            getPlaylistCursor(mAdapter.getQueryHandler(), null);
        }
    }

    return view;
}

From source file:org.xwalk.runtime.extension.api.device_capabilities.DeviceCapabilitiesStorage.java

private void registerIntentFilter() {
    mIntentFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    mIntentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    mIntentFilter.addDataScheme("file");
}

From source file:com.nadmm.airports.ActivityBase.java

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

    mDbManager = DatabaseManager.instance(this);
    mInflater = getLayoutInflater();//from w w w .  j  ava2  s . c  o m
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    mHandler = new Handler();

    mFilter = new IntentFilter();
    mFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    mFilter.addAction(Intent.ACTION_MEDIA_SHARED);
    mFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    mFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
    mFilter.addDataScheme("file");

    mExternalStorageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            externalStorageStatusChanged();
        }
    };

    if (Application.sDonationDone == null) {
        DonateDatabase db = new DonateDatabase(this);
        Cursor c = db.queryAllDonations();
        Application.sDonationDone = c.moveToFirst();
        db.close();
    }

    // Enable Google Analytics
    ((Application) getApplication()).getAnalyticsTracker();
}

From source file:net.micode.fileexplorer.FileViewActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mActivity = getActivity();/*from w  w w  . j a  va 2s  . co m*/
    // getWindow().setFormat(android.graphics.PixelFormat.RGBA_8888);
    mRootView = inflater.inflate(R.layout.file_explorer_list, container, false);
    ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity);

    mFileCagetoryHelper = new FileCategoryHelper(mActivity);
    mFileViewInteractionHub = new FileViewInteractionHub(this);
    Intent intent = mActivity.getIntent();
    String action = intent.getAction();
    if (!TextUtils.isEmpty(action)
            && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) {
        mFileViewInteractionHub.setMode(Mode.Pick);

        boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false);
        if (!pickFolder) {
            String[] exts = intent.getStringArrayExtra(EXT_FILTER_KEY);
            if (exts != null) {
                mFileCagetoryHelper.setCustomCategory(exts);
            }
        } else {
            mFileCagetoryHelper.setCustomCategory(new String[] {} /*folder only*/);
            mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE);

            mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {
                        Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0);
                        mActivity.setResult(Activity.RESULT_OK, intent);
                        mActivity.finish();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            });

            mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mActivity.finish();
                }
            });
        }
    } else {
        mFileViewInteractionHub.setMode(Mode.View);
    }

    mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list);
    mFileIconHelper = new FileIconHelper(mActivity);
    mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList,
            mFileViewInteractionHub, mFileIconHelper);

    boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD,
            !FileExplorerPreferenceActivity.isReadRoot(mActivity));
    Log.i(LOG_TAG, "baseSd = " + baseSd);

    String rootDir = intent.getStringExtra(ROOT_DIRECTORY);
    if (!TextUtils.isEmpty(rootDir)) {
        if (baseSd && this.sdDir.startsWith(rootDir)) {
            rootDir = this.sdDir;
        }
    } else {
        rootDir = baseSd ? this.sdDir : GlobalConsts.ROOT_PATH;
    }
    mFileViewInteractionHub.setRootPath(rootDir);

    String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity);
    Uri uri = intent.getData();
    if (uri != null) {
        if (baseSd && this.sdDir.startsWith(uri.getPath())) {
            currentDir = this.sdDir;
        } else {
            currentDir = uri.getPath();
        }
    }
    mFileViewInteractionHub.setCurrentPath(currentDir);
    Log.i(LOG_TAG, "CurrentDir = " + currentDir);

    mBackspaceExit = (uri != null) && (TextUtils.isEmpty(action)
            || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT)));

    mFileListView.setAdapter(mAdapter);
    mFileViewInteractionHub.refreshFileList();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    intentFilter.addDataScheme("file");
    mActivity.registerReceiver(mReceiver, intentFilter);

    updateUI();
    setHasOptionsMenu(true);
    return mRootView;
}