Android reverse image search - android

In my project i need to include searchs to a API Rest to query with a url that points to a jpg picture and it returns a list of urls with similar pictures.
Google Images performs via web like i am looking for, but the clients for Android that i have found (github projects) they work simply with an input text.
The simplest code would be something as below:
String inputUrlPic = "https://cdn.pixabay.com/photo/2014/03/14/20/13/dog-287420__340.jpg";
String[] returnedUrlPictures = null; //list of returned pictures similars to inputUrlPic
ReverseImageApi reverseImageApi = new ReverseImageApi();//My desired Api object
returnedUrlPictures = reverseImageApi.findSimilarPicturesFromUrl(inputUrlPic); //Ok, it would be an asynctask
So, my question is, exists a API or an Android client API to perform in this way?

Related

Load Google Static Map with Picasso on Android

I'm developing an app with Android Studio, I'd like to create a RecyclerView where I have an ImageView and upload a static image of a determining point on the map.
Like here: https://developers.google.com/maps/documentation/maps-static/intro
I tried to use this method with Picasso (Library that takes an image of a url and loads an ImageView) but nothing happens, with other urls of images on the internet that I used to test it worked and loaded in ImageView but with that nothing appears:
imageMap = findViewById(R.id.imageMap);
String lat = "-12.958811";
String lon = "-38.401606";
String url ="https://maps.googleapis.com/maps/api/staticmap?";
url+="&zoom=14";
url+="&size=330x130";
url+="&maptype=roadmap";
url+="&markers=color:green%7Clabel:G%7C"+lat+", "+lon;
url+="&key=MY_KEY";
Picasso.get().load(url).into(imageMap);
Does anyone know how to do this? With this or another method?
I have tried the methods in other posts reporting this problem but my url is correct in relation to the others.
Make sure you're using the right API key (use the one specifically for Android) and get a more detailed stacktrace by adding a simple success/error callback: Android: Picasso load image failed . how to show error message
You need to enable the billing option in your project. Google change the payment methods and now you need to enable this option in order to use some APIs.

Selecting paragraph tagged with itemprop=recipeInstructions using jsoup on android

I've tried my query in http://try.jsoup.org/ and it works fine. However, when I try it on android (4.2.2) it is returning a zero sized array.
The query I want is [itemprop=recipeInstructions].
The website I'm testing on is http://www.foodnetwork.co.uk/recipes/real-meatballs-and-spaghetti-674.html
My android code looks like
Document doc = Jsoup.connect("http://www.foodnetwork.co.uk/recipes/real-meatballs-and-spaghetti-674.html").get();
Elements recipe = doc.select("[itemprop=recipeInstructions]");
// recipe is a zero sized array :(
I'm linking against jsoup-1.7.3.jar
My android code works fine on the website http://www.foodnetwork.com/recipes/ina-garten/broccoli-and-bow-ties-recipe.html so I suspect it's a bug in the html or how jsoup parses the html of the first site.
Try to add the "User Agent".
Document doc = Jsoup.connect(url).userAgent("Mozilla/4.0").get();
Because, the server may return to different page according to different browser identification.
Try something like that:
Elements recipe = doc.select("p[itemprop = recipeInstructions]");

How can I upload multiple photos in one post on Google+ from G+ Android SDK?

I want to know how to upload multiple photos at a time thru google plus?
I found how to upload one photo and one message at a time from google plus sample code.
String action = "/?view=true";
Uri callToActionUrl = Uri.parse(getString(R.string.plus_example_deep_link_url) + action);
String callToActionDeepLinkId = getString(R.string.plus_example_deep_link_id) + action;
// Create an interactive post builder.
builder = new PlusShare.Builder(this, plusClient);
// Set call-to-action metadata.
builder.addCallToAction(LABEL_VIEW_ITEM, callToActionUrl, callToActionDeepLinkId);
// Set the target url (for desktop use).
builder.setContentUrl(Uri.parse(getString(R.string.plus_example_deep_link_url)));
// Set the target deep-link ID (for mobile use).
builder.setContentDeepLinkId(getString(R.string.plus_example_deep_link_id),
null, null, null);
// Set the message.
builder.setText("user message");
// Set the image
Uri uri = Uri.fromFile(new File("[user file path]"));
builder.setStream(uri);
Anyone knows about uploading multiple photos like facebook and twitter?
It should work with addStream() method, unfortunately... it doesn't work. Indeed it makes the application crash.
After a long search, I finally got it: it's not possible if using the simplified G+ SDK! (the one dedicated to Android).
There is a second one, included in the Google API family that you can find there:
http://code.google.com/p/google-api-java-client/wiki/APIs#Google+_API
This one will let you build more advanced post, included, several pic one.
Unfortunately the second SDK is much more low level, not dedicated to Android, it's a kind of Java abstraction over http request.
Regards

Google Drive Custom Thumbnail for Standard MIME Type

I have yet another pesky question for people who understand how Google Drive SDK works. On Android platform, I am creating my own custom thumbnails for JPEG image files ( thumbnail is a reduced JPG of the most important detail of the parent image ), The size is a bit non-standard - 384 x 128px, but well within limits stated in the documentation. So, the code goes like this:
// thumbnail
String myThumb = "test.tnl";
Thumbnail tn = new Thumbnail();
tn.setMimeType("image/jpeg");
tn.setImage(Base64.encodeBase64String(myThumb.getBytes()));
// define meta-data
File body = new File();
body.setTitle("test.jpg");
body.setDescription("bla bla");
body.setMimeType("image/jpeg");
body.setThumbnail(tn);
File gooFl = drvSvc.files()
.insert(body, new FileContent("image/jpeg", new java.io.File(test.jpg)))
.execute();
and executes flawlessly (there are more 'body' elements I don't list here) and everything works like a charm. But when I download the image, my thumbnail is gone, replaced by standard Google thumbnail - s220 type.
I did notice the documentation statement:
As with indexable text, Drive automatically generates thumbnails for many common file types. For shortcuts and other file types Drive can not render, you can provide a thumbnail image generated by your application.
Reading it ambiguously, I was hoping that by supplying my own thumbnail to a known MIME type, I will keep Google Drive from generating its standard one, but it probably is not the case. So the question remains. Is there a solution to my problem? Having custom thumbnails for standard "image/jpeg" MIME types? Or is there a work-around, perhaps another custom field I can stick some 10Kb of binary data in? I need the thumbnails in my Android viewer - another app.
Thank you, sean
Google Drive will only use custom thumbnails for non-standard MIME types, so you can't override the one for jpeg. Your app can use a custom file property to store and read proprietary data:
https://developers.google.com/drive/properties

serving blobstore image through app-engine endpoints api

I am building an app-engine endpoint api that takes picture from a user (android app) and saves it to blobstore programmatically. Then I save the blob_key in my datastore. The code goes like this:
First I received the image through my #endpoint.method as a messages.BytesField:
image_data = messages.BytesField(1, required=True)
Then I save to the blobstore like this:
from google.appengine.api import files
def save_image(data):
# Create the file
file_name = files.blobstore.create(mime_type='image/png')
# Open the file and write to it
with files.open(file_name, 'a') as f:
f.write('data')
# Finalize the file. Do this before attempting to read it.
files.finalize(file_name)
# Get the file's blob key
blob_key = files.blobstore.get_blob_key(file_name)
return blob_key # which is then saved to datastore
Now I want to serve the image back. I don't see how to fit the following code into my endpoints api:
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
resource = str(urllib.unquote(resource))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
In the end I imagine a serving procedure like this:
in #endpoints.method:
get blob_key from datastore
obtain image with blob_key
add image to StuffResponseMessage
send StuffResponseMessage to front-end (android app)
My approach is because I want to protect the privacy of my users. Any thoughts on how to do this well? My code snippets are generally from the google developer tutorial.
EDIT:
I don't see how I would pass the blob_key from the datastore to the following method to retrieve the image:
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
resource = str(urllib.unquote(resource))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
What's inside resource, anyway?
I believe resource is the BlobKey object of what you want to serve, as a string, retreived from url path. If you look at the source of google.appengine.ext.blobstore.BlobInfo the get method uses a function __normalize_and_convert_keys that takes an argument of BlobKey object OR string.
If the blob is an image, maybe it's best to send the serving url instead to your Android app, in StuffResponseMessage maybe in your case. From google's Serving a Blob doc:
If you are serving images, a more efficient and potentially less-expensive method is to use get_serving_url using the App Engine Images API rather than send_blob. The get_serving_url function lets you serve the image directly, without having to go through your App Engine instances.
So after you save the image, take the returned blob_key (as per your method save_image(data) above) to make a serving url, then in your Android app get the image from the returned url. That of course means exposing the image url without privacy protection.
If you want to do it with protection, use BlobReader class to read the blob with file like interface. You can't use the method/class from Serving a Blob example because you do it in a remote.Service subclass rather than a handler.

Categories

Resources