Created
January 25, 2012 00:36
-
-
Save ianloic/1673802 to your computer and use it in GitHub Desktop.
Rdio Search Intent Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.rdio.android.test; | |
import android.app.Activity; | |
import android.app.SearchManager; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.KeyEvent; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
public class MainActivity extends Activity { | |
Button button; | |
EditText searchInput; | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
View layout = inflater.inflate(R.layout.main, null); | |
button = (Button)layout.findViewById(R.id.go_button); | |
searchInput = (EditText)layout.findViewById(R.id.search_input); | |
/* Search on Enter in text entry */ | |
searchInput.setOnKeyListener(new View.OnKeyListener() { | |
public boolean onKey(View v, int keyCode, KeyEvent event) { | |
if ((event.getAction() == KeyEvent.ACTION_DOWN) && | |
(keyCode == KeyEvent.KEYCODE_ENTER)) { | |
doSearchWithQuery(searchInput.getText().toString()); | |
return true; | |
} | |
return false; | |
} | |
}); | |
button.setOnClickListener(new View.OnClickListener() { | |
public void onClick(View v) { | |
final String query = searchInput.getText().toString(); | |
doSearchWithQuery(query); | |
} | |
}); | |
setContentView(layout); | |
} | |
private void doSearchWithQuery(String query) { | |
if (query == null || "".equals(query)) return; | |
final Intent intent = new Intent("android.media.action.MEDIA_PLAY_FROM_SEARCH"); | |
intent.putExtra(SearchManager.QUERY, query); | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
startActivity(intent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment