Help is needed. In the toolbar there is a search where information will be entered and when you click on the keyboard, enter Google will open Google with the data entered. In no way can I understand in the documentation and examples how to make a search that should search for information in Google. At the moment, came up with the only way: transfer entered through the intent

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(**данные**)); startActivity(intent); 

but I do not understand how to get this data to make castes in a string for this method

  public Intent(String action, Uri uri, Context packageContext, Class<?> cls) { setAction(action); mData = uri; mComponent = new ComponentName(packageContext, cls); } 

It seems to me that there is some other way, a little clearer.

Here is my code:

 @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.menu_toolbar, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { transaction = manager.beginTransaction(); switch (item.getItemId()) { case R.id.action_map: transaction.replace(R.id.container, new MapsFragment()).commit(); return true; case R.id.action_search: return true; default: return super.onOptionsItemSelected(item); } } 

    1 answer 1

    Found a good article that describes an example of working with SearchManager

    The code now looks like this:

     @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.menu_toolbar, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { public boolean onQueryTextChange(String newText) { // this is your adapter that will be filtered return true; } public boolean onQueryTextSubmit(String query) { //Here u can get the value "query" which is entered in the search box. if (!query.isEmpty()) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/search?q=" + query)); startActivity(intent); } return true; } }; searchView.setOnQueryTextListener(queryTextListener); return super.onCreateOptionsMenu(menu); }