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.
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 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 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.
In my Android app, I log in using the Facebook SDK and display posts from the users' newsfeed. I want to give them the option to comment or like a post, but I don't want to implement that. So, my solution is to allow the user to click on the post, which will then load the post page in either the official Facebook App, or just the mobile facebook website. Either way is fine for me.
I googled around and was not able to find a suitable way to deliver an intent to launch the Facebook app to a specific post page. So, I decided to try to launch the browser and navigate to the mobile Facebook website to the specific post. I build the url string using information about the current user, the id of the post, and the id of the friend it belongs to. This url is exactly the same url I see when I browse to the page in my browser from my newsfeed. Like so:
String url = "http://m.facebook.com/#!/story.php?story_fbid=" + postId + "&id=" + friendId + "&_user=" + FBHelper.getCurrentUserId();
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
However, when the browser loads, I get a page that says "Sorry, something went wrong. We're working on getting this fixed as soon as we can." I have tried both touch.facebook.com and m.facebook.com.
I am looking for any solution that will either allow me to open the mobile site to the chosen post, or to launch the Facebook app to the chosen post activity.
I just figured this out. It turns out that the post id that I got from the json result of a newsfeed request to the graph api has extra information. The post id that I got from the newsfeed result is in the form "friendid_postid." In the link, however, the "story_fbid" tag should be set to just the postid portion. Then it works!
This is the code I used:
String postId = idTextView.getText().toString();
postId = postId.substring(postId.indexOf("_") + 1, postId.length());
String friendId = friendIdTextView.getText().toString();
String url = "http://m.facebook.com/#!/story.php?story_fbid=" + postId + "&id=" + friendId + "&_user=" + FBHelper.getCurrentUserId();
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
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);