I am trying to add a search bar into an Android app that will open a browser to search Google. How would this be done in the simplest way?
You need an Edittext and a Button and if someone click on the button get the text from the edittext (getText()), and cear the EditText. After that you can create the url string from "www.google.com/#q=" plus the text and finally you can do:
Uri uri = Uri.parse(urlString);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
That's all, I hope it's helped.
Related
I want to display google search results in my android app,When the user type word in editText and click search button to get google search results and shown in inside my app.I have no experience to do this. please help me anyone
private static final String GOOGLE_SERACH_URL = "https://www.google.com/search?q=";
Then simply append the key you want to search on google after the URL and load your query string in a WebView.
webView = (WebView) rootView.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(GOOGLE_SERACH_URL + searchKey);
Working example
https://github.com/hiteshsahu/Android-Universal-Web-Content-Loader
You can use Intent class with the action web search.
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String keyword= "your query here";
intent.putExtra(SearchManager.QUERY, keyword);
startActivity(intent);
For better learning you can follow example program.
I am making an android app and in that Can I send Intent to pass something to Google search and can display the search page result ?
I hope I am clearly specifying my question.
So, Please help me in this.
Thank you all in advance.
Assuming you are accepting the value from user in edit text.
String url = "http://www.google.com/#q=";
String query = edittext.getText().toString().trim();
String final_url = url + query;
Now on search button click, do the following
Uri uri = Uri.parse(final_url);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
This will launch your web browser and show you the google search result.
I am trying to get a button on my app go to the market place when clicked. Not to another app, but to my publisher area with all my apps. Can anyone help, it just seems to force close at the moment?
final String APP_MARKET_URL = "market://developer?pub=PUB+ID+HERE";
I think that the correct string is market://search?q=pub:PUB+ID+HERE
If your string is correct too, try doing it with this code
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_MARKET_URL));
market.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(market);
I have read the answer "How do I launch a URL in the browser from my Application on Android" but I am still confused.
------>
Basically I have a TextView that will be displaying different names of famous people, and what I want is, to perform a google search in the browser that searches for the text that is currently displayed in the TextView, when the user clicks on the TextView itself.
Thanks.
in onClickListner event write this code:
String url = textView.getText().toString();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Well, what I understand is that you want to launch Google search for the text when you click on the TextView. Here is a code to directly launch Google search of the text provided:
String searchKey = "Text From your TextView";
Intent search = new Intent(Intent.ACTION_WEB_SEARCH);
search.putExtra(SearchManager.QUERY, searchKey);
startActivity(search);
I'm implementing global search box extension (sth like SearchableDictionary sample in android sdk). Everything works fine - suggestions are displayed properly. Problem is that I want browser to start when user picks a suggestion. (each suggestion is a link)
Columns of my cursor contain SearchManager.SUGGEST_COLUMN_INTENT_DATA, and I use that to pass http link. My searchable xml contains default intent action set to: android:searchSuggestIntentAction="android.intent.action.VIEW". But when user hits the suggestion, my application is started instead of browser. What am I missing?
Regards!
You need to implement the search in the same app i.e Browser in your example. The SearchManager can only send intent to the current activity.
Btw, try to catch that intent which will be generated when the search item is selected and then open the browser from your activity.
Try to use this code. Rewrote the showResults function in the Searchable Dictionary sample code.
private void showResults(String query) {
Intent myIntent;
myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
startActivity(myIntent);
finish();
}