androidsearchquick-search

Launching webbrowser using search in android


I am making an android application that needs to open the webbrowser when the go button on quick search is pressed. How can i make this happen? that it starts the webbrowser? This is the code that i got so far:

public class SearchFunction extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final Intent queryIntent = getIntent();
    final String queryAction = queryIntent.getAction();
    if (Intent.ACTION_SEARCH.equals(queryAction)) {
        String searchKeywords = queryIntent.getStringExtra(SearchManager.QUERY);
        //Is it here that i can start intents/webbrowser???
    }
}
}

Solution

  • For how to do the search activity you have all the info here: http://developer.android.com/guide/topics/search/search-dialog.html

    Starting the browser:

    Intent i = new Intent(Intent.ACTION_VIEW, 
           Uri.parse("http://www.google.ro/search?q=" + searchKeywords.replace(' ', '+')));
    startActivity(i);
    

    Hope it helps.