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.
Related
I want to create an android app. When I click a row in the ListView, it should go to a website.
In the ListView I'll have my widgets such as TextView, ImageView etc...
For eg: "www.amazon.com"
I tried the following,
rowView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.EMPTY.parse("www.amazon.com"));
context.startActivity(i);
}
});
It successfully redirects to "www.amazon.com".
Here, how will the amazon people know that people are visiting their website using my app?
When you click a link, your browser loads the web page you clicked and tells the website where you came from. For example, if you clicked a link to an outside website on stackoverflow.com, the outside website would see the address of the stackoverflow.com question you came from. This information is contained in the HTTP referrer header.
To add this information you can use the following code, assuming you are using a WebView to display the website
String url = "http://www.amazon.com/";
Map<String, String> extraHeaders = new HashMap<String, String>();
extraHeaders.put("Referer", "http://www.yourwebsite.com");
WebView wv;
wv = (WebView) findViewById(R.id.webview);
wv.loadUrl(url, extraHeaders);
Using an Intent is not possible with the exception the user would use the default browser which supports this kind of code
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Bundle bundle = new Bundle();
bundle.putString("Referer", "http://www.yourwebsite.com");
browserIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
However if you simply have the WebView in your layout, with visibility invisible, and you do not overwrite the WebClient, i.e.wv.setWebViewClient(new MyWebViewClient());, you get the same behaviour as with the Intent
I've never worked with android apps so I don't know the exact implementation.
But what you could do is setting the header of your webrequest manually so you look like a desktopbrowser. If you're using chrome as a browser you can see what your headers are in the developers tools window under network
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.
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 was wondering if there is a way to start a Browser with a yahoo search query. For example user can select a certain word or phrase and click a button and the activity will start the browser with the yahoo search query.
The quickest way is with intents, like so:
String query = "my search terms";
String url = "http://search.yahoo.com/search?p=" + query;
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Android will automatically attempt to open this in the application associated with URLs which, by default, should be their default web browser.
Try appending the search keyword to Yahoo search api url and accessing it via uri onClick new button in your activity.
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);