Example usage for android.provider MediaStore INTENT_ACTION_MEDIA_SEARCH

List of usage examples for android.provider MediaStore INTENT_ACTION_MEDIA_SEARCH

Introduction

In this page you can find the example usage for android.provider MediaStore INTENT_ACTION_MEDIA_SEARCH.

Prototype

String INTENT_ACTION_MEDIA_SEARCH

To view the source code for android.provider MediaStore INTENT_ACTION_MEDIA_SEARCH.

Click Source Link

Document

Activity Action: Perform a search for media.

Usage

From source file:com.bayapps.android.robophish.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 *///from  w w w .ja va 2  s .  c  om
private void showNotification(String title, String subtitle, String mediaId) {
    Intent intent = new Intent(this, MusicPlayerActivity.class);
    intent.putExtra(MusicPlayerActivity.EXTRA_START_FULLSCREEN, false);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    //TEST
    intent.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    intent.putExtra("title", title);
    intent.putExtra("subtitle", subtitle);
    intent.putExtra("showid", "__TRACKS_BY_SHOW__/" + mediaId);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_allmusic_black_24dp).setContentTitle("There's a new Phish show!")
            .setContentText(title + ", " + subtitle).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(Integer.parseInt(mediaId), notificationBuilder.build());
}

From source file:org.musicmod.android.app.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();/*from w  w  w  . j a  va2s  . co  m*/

    String action = bundle != null ? bundle.getString(INTENT_KEY_ACTION) : null;
    String data = bundle != null ? bundle.getString(INTENT_KEY_DATA) : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = Uri.parse(data);
        if (data.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            MusicUtils.playAll(getActivity(), list, 0);
            getActivity().finish();
            return;
        } else if (data.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            return;
        } else if (data.startsWith("content://media/external/audio/artists/")) {
            // This is an artist, show the albums for that artist
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
            i.putExtra("artist", uri.getLastPathSegment());
            startActivity(i);
            return;
        }
    }

    mFilterString = bundle != null ? bundle.getString(SearchManager.QUERY) : null;
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_FOCUS) : null;
        String artist = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ARTIST) : null;
        String album = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ALBUM) : null;
        String title = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_TITLE) : null;
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (Audio.Albums.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (Audio.Artists.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
}

From source file:com.andrew.apolloMod.activities.QueryBrowserActivity.java

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    if (mAdapter != null) {
        getQueryCursor(mAdapter.getQueryHandler(), null);
    }/*from  w w  w .  j av  a2 s  .  c o  m*/

    Intent intent = getIntent();
    String action = intent != null ? intent.getAction() : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = intent.getData();
        String path = uri.toString();
        if (path.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            MusicUtils.playAll(this, list, 0);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/artists/")) {
            intent = new Intent(Intent.ACTION_VIEW);

            Bundle bundle = new Bundle();
            bundle.putString(MIME_TYPE, Audio.Artists.CONTENT_TYPE);
            bundle.putString(ARTIST_KEY, uri.getLastPathSegment());
            bundle.putLong(BaseColumns._ID, ApolloUtils.getArtistId(uri.getLastPathSegment(), ARTIST_ID, this));

            intent.setClass(this, TracksBrowser.class);
            intent.putExtras(bundle);
            startActivity(intent);
            return;
        }
    }

    mFilterString = intent.getStringExtra(SearchManager.QUERY);
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = intent.getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS);
        String artist = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST);
        String album = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM);
        String title = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE);
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (focus.equals(Audio.Albums.ENTRY_CONTENT_TYPE)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (focus.equals(Audio.Artists.ENTRY_CONTENT_TYPE)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    setContentView(R.layout.listview);
    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
    if (mAdapter == null) {
        mAdapter = new QueryListAdapter(getApplication(), this, R.layout.listview_items, null, // cursor
                new String[] {}, new int[] {}, 0);
        setListAdapter(mAdapter);
        if (TextUtils.isEmpty(mFilterString)) {
            getQueryCursor(mAdapter.getQueryHandler(), null);
        } else {
            mTrackList.setFilterText(mFilterString);
            mFilterString = null;
        }
    } else {
        mAdapter.setActivity(this);
        setListAdapter(mAdapter);
        mQueryCursor = mAdapter.getCursor();
        if (mQueryCursor != null) {
            init(mQueryCursor);
        } else {
            getQueryCursor(mAdapter.getQueryHandler(), mFilterString);
        }
    }

    LinearLayout emptyness = (LinearLayout) findViewById(R.id.empty_view);
    emptyness.setVisibility(View.GONE);
}

From source file:com.bayapps.android.robophish.ui.MusicPlayerActivity.java

protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
    String mediaId = null;/*from  w  ww . j  av  a  2 s .  c  o m*/
    // check if we were started from a "Play XYZ" voice search. If so, we save the extras
    // (which contain the query details) in a parameter, so we can reuse it later, when the
    // MediaSession is connected.
    if (intent.getAction() != null
            && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
        mVoiceSearchParams = intent.getExtras();
        LogHelper.d(TAG, "Starting from voice search query=",
                mVoiceSearchParams.getString(SearchManager.QUERY));
    } else if (intent.getAction() != null && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_SEARCH)) {

        navigateToBrowser(null, null, null);

        Bundle extras = intent.getExtras();
        String title = extras.getString("title");
        String subtitle = extras.getString("subtitle");
        mediaId = extras.getString("showid");

        String year = subtitle.split("-")[0];
        //browse to year...
        navigateToBrowser(null, null, MediaIDHelper.MEDIA_ID_SHOWS_BY_YEAR + "/" + year);

        //now launch as show
        navigateToBrowser(title, subtitle, mediaId);
    }

    else {
        if (savedInstanceState != null) {
            // If there is a saved media ID, use it
            mediaId = savedInstanceState.getString(SAVED_MEDIA_ID);
        }
        navigateToBrowser(null, null, mediaId);
    }
}

From source file:org.yammp.fragment.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();// ww  w  .  j  a v a2 s.c  o  m

    String action = bundle != null ? bundle.getString(INTENT_KEY_ACTION) : null;
    String data = bundle != null ? bundle.getString(INTENT_KEY_DATA) : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = Uri.parse(data);
        if (data.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            mUtils.playAll(list, 0);
            getActivity().finish();
            return;
        } else if (data.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            return;
        } else if (data.startsWith("content://media/external/audio/artists/")) {
            // This is an artist, show the albums for that artist
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
            i.putExtra("artist", uri.getLastPathSegment());
            startActivity(i);
            return;
        }
    }

    mFilterString = bundle != null ? bundle.getString(SearchManager.QUERY) : null;
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_FOCUS) : null;
        String artist = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ARTIST) : null;
        String album = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ALBUM) : null;
        String title = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_TITLE) : null;
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (Audio.Albums.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (Audio.Artists.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
}

From source file:org.yammp.app.AlbumFragment.java

private void doSearch() {

    CharSequence title = null;//  w w w .ja  v  a 2 s .co  m
    String query = null;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    title = mCurrentAlbumName;
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentArtistNameForAlbum)) {
        query = mCurrentAlbumName;
    } else {
        query = mCurrentArtistNameForAlbum + " " + mCurrentAlbumName;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistNameForAlbum);
    }
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentAlbumName)) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, mCurrentAlbumName);
    }
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}

From source file:org.peterbaldwin.vlcremote.fragment.PlaylistFragment.java

private void searchForItem(PlaylistItem item) {
    if (item instanceof Track) {
        Track track = (Track) item;
        String title = track.getTitle();
        String artist = track.getArtist();
        String query = artist + " " + title;

        Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
        intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
        intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, title);
        intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
        intent.putExtra(SearchManager.QUERY, query);

        String chooserTitle = getString(R.string.mediasearch, title);
        startActivity(Intent.createChooser(intent, chooserTitle));
    }//  w  ww .  ja  v  a  2  s. c o  m
}

From source file:org.yammp.app.ArtistFragment.java

private void doSearch() {

    CharSequence title = null;// www  .  j a v  a2s. c om
    String query = null;

    if (mCurrentGroupArtistName == null || MediaStore.UNKNOWN_STRING.equals(mCurrentGroupArtistName))
        return;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    title = mCurrentGroupArtistName;

    query = mCurrentGroupArtistName;
    i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentGroupArtistName);
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}

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

void doSearch() {
    CharSequence title = null;/*from w w w. j av a 2s  .  c  o  m*/
    String query = null;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (mCurrentArtistId != null) {
        title = mCurrentArtistName;
        query = mCurrentArtistName;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistName);
        i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
    } else {
        if (mIsUnknownAlbum) {
            title = query = mCurrentArtistNameForAlbum;
        } else {
            title = query = mCurrentAlbumName;
            if (!mIsUnknownArtist) {
                query = query + " " + mCurrentArtistNameForAlbum;
            }
        }
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistNameForAlbum);
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, mCurrentAlbumName);
        i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE);
    }
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}

From source file:org.yammp.fragment.ArtistFragment.java

private void doSearch(String artist, String album) {

    CharSequence title = null;// w  ww.  jav  a  2 s .  co  m
    String query = null;

    boolean isUnknownArtist = artist == null || MediaStore.UNKNOWN_STRING.equals(artist);
    boolean isUnknownAlbum = album == null || MediaStore.UNKNOWN_STRING.equals(album);
    if (isUnknownArtist && isUnknownAlbum)
        return;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    title = album != null ? album : artist;
    query = album != null ? album : artist;

    if (!isUnknownArtist) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    }
    if (!isUnknownAlbum) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
    }
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}