Вопрос

I am trying to put a simple Google Search in my app. I found this code but it's not exactly what I am searching for. Below the search comes from a given url.

String url = "http://www.google.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i); 

The thing is that I would like to get the search text from user and if possible without starting a new Activity like this one:

Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String term = editTextInput.getText().toString();
intent.putExtra(SearchManager.QUERY, term);
startActivity(intent);
Это было полезно?

Решение

Get the text from the user and place that in the URI, then start the intent.

String url = "http://www.google.com/search?q=" + userText;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top