I am developing an android application for the first time.
I am able to do a www.google.com search with this code:
public void onSearchClick(View v) {
try {
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String term = editText.getText().toString();
intent.putExtra(SearchManager.QUERY, term);
startActivity(intent);
} catch (Exception ex) {
}
}
But is it also possible to do a search like that on images.google.com (with a word that was filled in the editText-widget)?
Thanks in advance.
a bit late to the party.
I was trying to do much the same thing, stumbled on this Android: Google Images Search Results
,and found that the following query should be more "elegant" - but of course no guarantee that Google would not change it -:
Take "cheetah" as an example for query,
https://www.google.com/search?tbm=isch&q=cheetah
should do the trick.
This should have come close to Shashank Kadne's suggestion in the comment above.
I don't find an elegant way. But you can use this :) intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://images.google.com/search?num=10&hl=en&site=&tbm=isch&source=hpāā&biw=1366&bih=667&q=cars&oq=cars&gs_l=img.3..0l10.748.1058.0.1306.4.4.0.0.0.0.165āā.209.2j1.3.0...0.0...1ac.1.8RNsNEqlcZc")); where q='Your_search_text'
Related
To validate email I am using following method i.e. official java email package
public static boolean isValidEmailAddress(String email) {
boolean result = true;
try {
InternetAddress emailAddr = new InternetAddress(email);
emailAddr.validate();
} catch (AddressException ex) {
result = false;
}
return result;
}
But above method also considers true for even "user#localhost.com", "user#10.9.8.7? I will be grateful if someone please help me out in removing above all these while validating email id of a user? I searched in google but could not find any solution. Many thanks in advance
The official Java email package considers things like user#localhost.com and user#10.9.8.7 as valid email addresses, since they are according to the RFC. Like the people who commented said, it would be best to figure out what rules you're trying to implement for your validation and go from there.
I'm creating an app where I get a youtube search. It is currently working ok, I just want to show better results, by sorting them by title name.
I got a VideoListResponse with 50 items
VideoListResponse videoListResponse = null;
try {
videoListResponse = mYouTubeDataApi.videos()
.list(YOUTUBE_VIDEOS_PART)
.setFields(YOUTUBE_VIDEOS_FIELDS)
.setKey(ApiKey.YOUTUBE_API_KEY)
.setId(TextUtils.join(",", videoIds)).execute();
} catch (IOException e) {
e.printStackTrace();
}
and I want to sort them by title. Let me show an image of the item list:
Well, the YouTube API already supports ordering the results by title. You won't have to do anything on your end....
https://developers.google.com/youtube/v3/docs/search/list#parameters
You could retrieve the List within and sort that:
List<Video> items = videoListResponse.getItems();
items.sort(Comparator.comparing(e -> e.getSnippet().getTitle()));
Hopefully someone can help me here. I have a project that I'm doing, yes it is homework so I hope that doesn't hurt my chances of an answer here. I'm supposed to write an app that collects data from bbyopen api. Best Buys web api, it delivers details about stores in your area. Any way I've gotten a response from the server that I'm certain contains the correct information as I've displayed it in logcat using System.out.println(). However, what I would like to do is turn this string into an xml document, parse out the name of the store, it's address and then display it in a text view in a new activity.
Here is the code I'm using to parse the string and put the proper data into an array which is passed to a new activity. I'm certain that nothing is actually passed to the new activity and I'm unsure whether or not the array is even being built. Any help would be greatly appreciated.
public void callback(String serviceResult){
System.out.println(serviceResult);
try {
XmlPullParserFactory parserCreator = XmlPullParserFactory.newInstance();
parserCreator.setNamespaceAware(true);
XmlPullParser parser = parserCreator.newPullParser();
parser.setInput(new StringReader(serviceResult));
int eventType = parser.getEventType();
while (eventType != parser.END_DOCUMENT){
String name = "";
String address = "";
if ((eventType == XmlPullParser.START_TAG)&& (parser.getName().equals("longName"))){
name = parser.getName();
}
if ((eventType == XmlPullParser.START_TAG)&& (parser.getName().equals("address"))){
address = parser.getName();
Store store = new Store(name, address);
arrStore.add(store);
System.out.println(arrStore);
}
else
parser.nextTag();
}
} catch (Exception e) {
}
Intent intent = new Intent(getApplicationContext(),StoreList.class);
intent.getStringArrayListExtra(arrStore.toString(), "key");
startActivity(intent);
}
I then receive the intent in the new activity like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_store_list);
getIntent();
ArrayList<String> store = getIntent().getStringArrayListExtra("key");
}
However trying to do a print line on the ArrayList store, in the new activity results in a null pointer error. I suspect that is because the array is empty..?
If it helps here is what the XML that I am receiving looks like and it is being sent as a string the parser.
<stores warnings="Distances are in terms of miles (default)" currentPage="1" totalPages="1" from="1" to="4" total="4" queryTime="0.006" totalTime="0.011" >
<store>
<longName>Best Buy - Toledo II</longName>
<address>1405 Spring Meadows Dr</address>
</store>
<store>
<longName>Best Buy - Perrysburg</longName>
<address>10017 Fremont Pike</address>
</store>
<store>
<longName>Best Buy - Toledo</longName>
<address>4505 Monroe St</address>
</store>
<store>
<longName>Best Buy Mobile - Franklin Park</longName>
<address>5001 Monroe Street</address>
</store>
</stores>
The error is here:
Intent intent = new Intent(getApplicationContext(),StoreList.class);
intent.getStringArrayListExtra(arrStore.toString(), "key");
startActivity(intent);
Try: putStringArrayListExtra().
Ok, so what im trying to see if can be done. So i have a basic form submission for my application. Where the user can fill out some information such as a support request. This consists of several edit texts and view texts. Then its has a little text builder code in it to merge the text together and intent's to the android system for output via email.
So what i want to know is how i can add a image into this factor.
public void onClick(View v) {
String[] recipients = new String[]{"email#email.com", "email#email.com",};
String subject = textSubject.getText().toString();
String message = "Name:\n" + nametext.getText().toString();
message += "\n\nEmail:\n" + emailtext.getText().toString();
message += "\n\nContact#:\n" + phonetext.getText().toString();
message += "\n\nTopic:\n" + topictext.getText().toString();
message += "\n\nDescription:\n" + detailstext.getText().toString();
message += "\n\n" + sentby.toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
//email.putExtra(Intent.EXTRA_CC, new String[]{ to});
//email.putExtra(Intent.EXTRA_BCC, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
//need this to prompts email client only
email.setType("message/rfc822");
//plain text
email.setType("text/plain");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
finish();
}
});
So here is the example code for the string builder code to merge whats being typed inside the edit text forms on the xml layout file.
Now what im trying to figure how to do, is what code i would need to add a insert image button on my xml layout, the code to select the image from the user's file manager or gallery app and then how i could add that into the overall intent to send via email.
Any suggestions, feedback, source code examples and anything helps. Thanks in advance.
UPDATE
i have found the below code, and want to know if anybody has used this and if it will work in my above code.
sendIntent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
you need to use android.net.Uri
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mysong.mp3"));
it's work to attache file to email.
I have downloaded google map application on sonyerricsom T700 mobile its working fine,its java application.So as per my understanding that is also using Location API.
This link shows that it does not have GPS.
But it is showing map and even locating photo's clicked on device on google map.
So I am tried below code in j2me using Location API(JSR-179).Its working fine on emulator.
But when I am trying the same on Sony erisccon T700 mobile its giving below exception:
Exception:
javax.microedition.location.LocationException:All service providers are out of service.
Code:
try {
// Create a Criteria object for defining desired selection criteria
Criteria cr = new Criteria();
LocationProvider lp = LocationProvider.getInstance(cr);
l = lp.getLocation(60);
c = l.getQualifiedCoordinates();
//cityMap.setCategories(selectedCategories);
if (c != null) {
// use coordinate information
double lat = c.getLatitude();
//latitude="";
latitude = ""+lat;
Latitude.setString(latitude);
double lon = c.getLongitude();
longitude =""+lon;
Longitude.setString(longitude);
}
}
catch (LocationException e) {
alert = new Alert("LocationException");
alert.setString("Unable to retrive location information:" + e);
alert.setTimeout(2000);
display.setCurrent(alert);
// not able to retrive location information
//e.printStackTrace();
} catch (InterruptedException ie) {
alert = new Alert("InterruptedException");
alert.setString("Operation Interrupted:" + ie);
alert.setTimeout(2000);
display.setCurrent(alert);
}
}
Please suggest me any solution for this...
Thank and regards.
Yeah, I bet it's not exact location like you would get from GPS.
Google has other ways of finding your location... it's probably using Cell ID. Luckily Sony Ericsson handsets are quite easy to find Cell ID from, see here. Once you have it, you can look it up in a cell ID database to find location.