Example usage for android.content Intent ACTION_MEDIA_SCANNER_FINISHED

List of usage examples for android.content Intent ACTION_MEDIA_SCANNER_FINISHED

Introduction

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

Prototype

String ACTION_MEDIA_SCANNER_FINISHED

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

Click Source Link

Document

Broadcast Action: The media scanner has finished scanning a directory.

Usage

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");
    }//  w  ww .jav a 2s. c om

    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 {//w  w w. j ava  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:com.android.music.AlbumBrowserActivity.java

/** Called when the activity is first created. */
@Override/*ww  w  .  jav  a2 s.  co 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  w  w .j  a  v  a2 s. c  om
    }

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

public void onServiceConnected(ComponentName name, IBinder service) {
    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);

    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new TrackListAdapter(getActivity().getApplication(), // need to use application context to avoid leaks
                this, mEditMode ? R.layout.edit_track_list_item : R.layout.track_list_item, null, // cursor
                new String[] {}, new int[] {}, "nowplaying".equals(mPlaylist),
                mPlaylist != null && !(mPlaylist.equals("podcasts") || mPlaylist.equals("recentlyadded")));
        mTrackList.setAdapter(mAdapter);
        //getActivity().setTitle(R.string.working_songs);
        getTrackCursor(mAdapter.getQueryHandler(), null, true);
    } else {//w ww . ja v  a  2s.co  m
        mTrackCursor = mAdapter.getCursor();
        // If mTrackCursor 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 (mTrackCursor != null) {
            init(mTrackCursor, false);
        } else {
            //getActivity(). setTitle(R.string.working_songs);
            getTrackCursor(mAdapter.getQueryHandler(), null, true);
        }
    }
    if (!mEditMode) {
        MusicUtils.updateNowPlaying(getActivity());
    }
}

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

public void handleMediaReceiver() {
    storageReceiver = new BroadcastReceiver() {
        @Override/* w ww  .j ava  2  s.  com*/
        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);
}