1

I am not using a SearchManager, but I have built my own custom search activity. I want this to be shown when the user clicks on the Search button. How can I do this?

Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
  • 1
    possible duplicate of [android start user defined activity on search button pressed @ handset](http://stackoverflow.com/questions/1912947/android-start-user-defined-activity-on-search-button-pressed-handset) – Christopher Orr Sep 24 '10 at 20:11

3 Answers3

0

If I understand you correctly, you are asking how to launch your search activity. Create an onClickListener for your button and an EditText field for the user to input text. Query the intent in your search activity to get whatever the user was searching for when the user clicks on the "search" button.

 EditText et = new EditText(this);

 public void onClick(View v){
     String searchText = et.getText();
     Intent intent = new Intent(this, com.example.app.SearchActivity.class);
     intent.putExtra("searchQuery", searchText);
     startActivity(intent);
 }

http://developer.android.com/guide/appendix/faq/commontasks.html#opennewscreen

Chris
  • 94
  • 3
  • I know how to start my activity, but I would like it to be tied to the Search Button on all phones. So when you click on the magnifying glass button, it will call my activity. – Sheehan Alam Sep 24 '10 at 19:52
0

Inside of your own application, you can do this via monitoring onKeyDown(), AFAIK.

Inside other applications, this is not possible except via custom firmware.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Not sure if this will work or not, but have you tried extending a BroadcastReceiver that can catch the search's intent? Checking the developer reference the intent seems to be "android.search.action.GLOBAL_SEARCH". So, you'll have a Receiver class like:

public class MyIntentReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.search.action.GLOBAL_SEARCH")) {
      Intent sendIntent = new Intent(context, MySearchActivity.class)
      context.startActivity(intent);
    }
  }
}

In your manifest, between the application tags, you should have

<receiver android:name="MyIntentReceiver">
    <intent-filter>
        <action android:name="android.search.action.GLOBAL_SEARCH" />
    </intent-filter>
</receiver>
AndrewKS
  • 3,603
  • 2
  • 24
  • 33