Android : Calling Google Now search programmatically from Android application

on Tuesday, March 24, 2015


I have a text box and a button. When I click on the button Google Now is triggered with the text in the text box. I am using the below function to launch the Google Now with the text.



public void searchWeb(String query)
{
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, query);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
startActivity(intent);
}


The problem is I could open the Google Now with my text only when it's not in running state. When it's in the running state,the Google Now page opens but the search query is not updated with the latest one.


Am I missing something?


0 comments:

Post a Comment