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);
Related
I am trying to perform a search on Deezer by sending the following intent:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.deezer.com/search/" + query));
this.startActivity(intent);
In a previous version the web browser opened with a link saying "Open in Deezer" (or the like).
But in the current version this doesn't work anymore.
Is there any way to open the Deezer app and perform a search?
I have already tried the following (without success):
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://search/" + query));
this.startActivity(intent);
There are many deeplinks you can use to search for content inside the Deezer app. You do have the basic search like this :
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://www.deezer.com/search/" + query));
this.startActivity(intent);
But you can also be more precise :
// Search for an artist, will display the best match
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer-query://www.deezer.com/artist?query" + query));
this.startActivity(intent);
// Search for an album, will display the best match
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer-query://www.deezer.com/album?query" + query));
this.startActivity(intent);
// Search for a track, will display the best match
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer-query://www.deezer.com/track?query" + query));
this.startActivity(intent);
I believe it should be
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://www.deezer.com/search/" + query));
this.startActivity(intent);
The scheme of the Uri needs to be deezer. You have set it as http.
Try this. This should work.
I want to implement a search function that open the default browser and search the passed string
public void searchOnGoogle(String keywords){
---
}
Is there a way using intent filter or I must implement everything by myself?
String query = URLEncoder.encode(keywords, "utf-8");
String url = "http://www.google.com/search?q=" + query;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
How can I open a url in the android web browser from my application on clicking a button.
I tried this :
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));
startActivity(myIntent);
but I am getting exception:
but I got an Exception :
"No activity found to handle Intent{action=android.intent.action.VIEW data =www.google.com"
You are doing it fundamentally correct, you just need to include the full url.
String strURL="http://www.google.com";
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));
startActivity(myIntent);
Basically, the http is the protocol. It is the computer's way of trying to figure out how you want to open it. You might also be interested in https, if you want a secure connection over SSL.
Almost seems like this would be useful to read... from the page:
Uri uri = Uri.parse("http://androidbook.blogspot.com");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uri);
startActivity(launchBrowser);
There is a second way, involving the WebView, but that seems like it's not your question. Hope this helped.
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Try this:
String strURL = "http://www.google.com";
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));
startActivity(myIntent);
As for the missing "http://" I'd just do something like this:
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
String url = "<html><body>hello World</body></html>";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
how can i load the HTML source code in the browser? Please kindly explain with an example.
Intent i = new Intent();
// MUST instantiate android browser, otherwise it won't work
i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
i.setAction(Intent.ACTION_VIEW);
String html = "<html><body>hello World</body></html>";
// May work without url encoding, but I think is advisable
// URLEncoder.encode replace space with "+", must replace again with %20
String dataUri = "data:text/html," + URLEncoder.encode(html).replaceAll("\\+","%20");
i.setData(Uri.parse(dataUri));
startActivity(i);
I was wondering if there is an easier way (or any way) to start a Browser with a Google 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 Google search query.
Thank you.
The Intent class defines an action specifically for web searches:
http://developer.android.com/reference/android/content/Intent.html#ACTION_WEB_SEARCH
Here's an example of how to use it:
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, query); // query contains search string
startActivity(intent);
You can do this quite easily with a few lines of code (assuming you want to search Google for 'fish'):
String escapedQuery = URLEncoder.encode(query, "UTF-8");
Uri uri = Uri.parse("http://www.google.com/#q=" + escapedQuery);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Otherwise, if you would rather start up your own Activity to handle the browsing, you should be able to do so with a WebView: http://developer.android.com/reference/android/webkit/WebView.html
I think the better answer here is #zen_of_kermit's. It would be nice though, if Android allowed a user to provide the Search engine has an extra though for the ACTION_WEB_SEARCH, rather than just using Google.
the # gave me trouble:
Uri uri = Uri.parse("https://www.google.com/search?q="+query);
Intent gSearchIntent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(gSearchIntent);
I recently tried this. This appears to work fine. If any modifications to be done let me know as I am new to android development.
mEdit = (EditText)findViewById(R.id.editText);
in your click view,
String q = mEdit.getText().toString();
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH );
intent.putExtra(SearchManager.QUERY, q);
startActivity(intent);
String Search= null;
try {
Search= URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Uri uri = Uri.parse("http://www.google.com/#q=" + Search);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});