How to search for images in Android Programmatically? - android

I have some EditTexts in my Activity.First text the for the title, second is for author.Now the user loose focus from the second edittext ie author.I want to get the images related to that content (title and author).So what I did, I concat the title and author name and make HTTP request using Volley.And I print that response.But the response is so unpredictable that I can not fetch the images from it.
try {
String googleImageUrl = "http://images.google.com/images?q=";
String query = URLEncoder.encode(title + " " + author, "utf-8");
String url = googleImageUrl + query;
Toast.makeText(context, url, Toast.LENGTH_SHORT).show();
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
post_des.setText("Response is: " + response);
Log.i("Show me something awesome dude", response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
post_des.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
And the responce is like this:
Response is: <!doctype html><html itemscope="" itemtype="http://schema.org/SearchResultsPage" lang="en-IN"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><link href="/images/branding/product/ico/googleg_lodp.ico" rel="shortcut icon"><title>something something - Google Search</title><style>#gb{font:13px/27px Arial,sans-serif;height:30px}#gbz,#gbg{position:absolute;white-space:nowrap;top:0;height:30px;z-index:1000}#gbz{left:0;padding-left:4px}#gbg{right:0;padding-right:5px}#gbs{background:transparent;position:absolute;top:-999px;visibility:hidden;z-index:998;right:0}.gbto #gbs{background:#fff}#gbx3,#gbx4{background-color:#2d2d2d;background-image:none;_background-image:none;background-position:0 -138px;background-repeat:repeat-x;border-bottom:1px solid #000;font-size:24px;height:29px;_height:30px;opacity:1;filter:alpha(opacity=100);position:absolute;top:0;width:100%;z-index:990}#gbx3{left:0}#gbx4{right:0}#gbb{position:relative}#gbbw{left:0;position:absolute;top:30px;width:100%}.gbtcb{position:absolute;visibility:hidden}#gbz .gbtcb{right:0}#gbg .gbtcb{left:0}.gbxx{display:none........like wise
I was expecting to get a Html doc.
So how to make a HTTP request for images with the content(title and author).
Edit
In layman language,
Suppose I am on images.google.com, and I typed in something in search bar, and make a search, now I want the data that Google return as the Url of the images on that webpage(I am doing all this in backend not showing it to the user.)
I think it is now understandable :)

You got html but of the whole search page. You can retrieve pictures' urls with css selectors and [JSOUP library][2] (easy to use). Just go to Chrome browser and then choose Settings - More tools - Developer tools. Then click the right mouse button on a picture and choose inspect and you'll see which container is for the pictures and what div contains src url of the images and then you right click this div and choose copy css selector. Then work with the library.
But be aware, it's not practical cause if they change the page html your code will beak. You better use specific api for this purpose, like Google Custom Search API as it was suggested in comments above.
To put image into UI you need to get its url address and then you can use Glide or Picasso or even Volley
// Retrieves an image with Volley specified by the URL, displays it in the UI.
ImageRequest request = new ImageRequest(url,
new Response.Listener<Bitmap>() {
#Override
public void onResponse(Bitmap bitmap) {
mImageView.setImageBitmap(bitmap);
}
}, 0, 0, null,
new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
mImageView.setImageResource(R.drawable.image_load_error);
}
});
EDIT:
Here is CSS selector for all images on the google search page img.rg_ic. Using Jsoup and this selector you'll get access to all the image tags on the page
Jsoup example:
Document doc = Jsoup.connect(your link string).get();
Elements imgs = doc.select("img");//the selector
for (Element img : imgs) {
//add img urls to String array and then use to get imgs with them
String s = img.attr("src");
arr.add(s);
}
[![enter image description here][3]][3]
EDIT2 :
Your code with changes:
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
TextView textView;
String googleImageUrl = "https://www.google.co.in/search?biw=1366&bih=675&tbm=isch&sa=1&ei=qFSJWsuTNc-wzwKFrZHoCw&q=";
ArrayList<String> urls = new ArrayList<>();
String url;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AsyncTask.execute(new Runnable() {
#Override
public void run() {
Log.i("someething" , "something");
getImages("https://www.google.co.in/search?biw=1366&bih=675&tbm=isch&sa=1&ei=qFSJWsuTNc-wzwKFrZHoCw&q=somethingsomething");
}
});
}
private void getImages(String url) {
Document doc = null;
try{
doc = Jsoup.connect(url).get();
}catch (IOException e){
e.printStackTrace();
}
Elements imgs = doc.select("img");
System.out.println("Damn images"+imgs);
for (Element img : imgs){
Log.d("image-src", img.attr("data-src"));//changed `src` to `data-src`
}
}
}

You can get a List of google search images using Jsoup .،. see official site here https://jsoup.org/
/**
* Extract images from google as ArrayList.
*
* #param searchQuery is the string to search for
* #return returnedURLS is the List of urls
*/
private List<String> extractImagesFromGoogle(String searchQuery) throws IOException {
final String encodedSearchUrl = "https://www.google.com/search?q=" + URLEncoder.encode(searchQuery, "UTF-8") + "&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiUpP35yNXiAhU1BGMBHdDeBAgQ_AUIECgB";
Document document = Jsoup.connect(encodedSearchUrl).get();
String siteResponse = document.toString();
List<String> returnedURLS = new ArrayList<String>();
// parse the object and query the values (the urls) for specific keys ("ou")
Pattern pattern = Pattern.compile("\"ou\":\"(.*?)\"");
Matcher matcher = pattern.matcher(siteResponse);
while (matcher.find()) {
returnedURLS.add(matcher.group(1));
}
return returnedURLS;
}
// Test it now:
List<String> retrievedURLS = new ArrayList<String>();
try {
retrievedURLS = extractImagesFromGoogle("pyramids");
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(">> List Size: " + retrievedURLS.size());
System.out.println(">> List of images urls: " + retrievedURLS);

Related

Dictionary app using Oxford Dictionary API

I am trying to make a dictionary application using Oxford Dictionary api. There is something wrong with my code JSON. Can anyone tell me how do I extract only the definition of the searched word, rather getting the whole JSON file
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class MainActivity extends AppCompatActivity {
private static final String APP_ID= "59028fc6";
private static final String API_KEY = "ad3e310307d7b2f8bf474c45e1efd01f";
private static final String TAG = MainActivity.class.getSimpleName();
private OkHttpClient okHttpClient;
private EditText textInput;
private Button submitButton;
private TextView definitionView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initialize ok http
okHttpClient = new OkHttpClient();
textInput = findViewById(R.id.textInput);
submitButton = findViewById(R.id.submitButton);
definitionView = findViewById(R.id.textMeaning);
submitButton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View view) {
findMeaningOfEnteredWord();
}
});
}
private void findMeaningOfEnteredWord() {
String word = textInput.getText().toString();
if (word.isEmpty()) {
Toast.makeText(this, "Nothing entered", Toast.LENGTH_SHORT).show();
return;
}
// create url from the word
String lowerCaseWord = word.toLowerCase();
String httpRequestUrl = "https://od-api.oxforddictionaries.com:443/api/v1/entries/en/" + lowerCaseWord;
// make request with REST url
new RequestAsyncTask().execute(httpRequestUrl);
}
private class RequestAsyncTask extends AsyncTask<String, Integer, String> {
#Override
protected String doInBackground(String... params) {
String requestUrl = params[0];
Request request = new Request.Builder()
.url(requestUrl)
.addHeader("Accept", "application/json")
.addHeader("app_id", APP_ID)
.addHeader("app_key", API_KEY)
.build();
Response response = null;
try {
response = okHttpClient.newCall(request).execute();
return response.body().string();
} catch (IOException ex) {
Log.e(TAG, "caught error: " + ex.getMessage());
}
return "";
}
#Override
protected void onPostExecute(String result) {
try {
JSONObject responseAsJson = new JSONObject(result);
JSONArray results = responseAsJson.getJSONArray("results");
if (results.length() > 0) { // valid definitions were found
String lexicalEntries = results.getJSONObject(0).getString("lexicalEntries");
definitionView.setText(lexicalEntries);
}
Log.d(TAG, " " + responseAsJson.toString());
} catch (Exception ex) {
Log.d(TAG, "exception during json parsing: " + ex.getMessage());
}
}
}
}
JSON:
{"id":"aeroplane",
"language":"en",
"lexicalEntries": [
{
"entries": [{"etymologies":["late 19th century: from French aéroplane, from aéro- ‘air’ + Greek -planos ‘wandering’"],
"grammaticalFeatures":[{"text":"Singular","type":"Number"}],
"homographNumber":"000",
"senses":[{"crossReferenceMarkers":["North American term airplane"],
"crossReferences":[{"id":"airplane","text":"airplane","type":"see also"}],
"definitions":["a powered flying vehicle with fixed wings and a weight greater than that of the air it displaces."],
"domains":["Aviation"],
"id":"m_en_gbus0013220.005",
"regions":["British"],
"short_definitions":["powered flying vehicle with fixed wings"],
"thesaurusLinks":[{"entry_id":"plane","sense_id":"t_en_gb0011151.001"}]}]}],"language":"en","lexicalCategory":"Noun","pronunciations":[{"audioFile":"http:\/\/audio.oxforddictionaries.com\/en\/mp3\/aeroplane_gb_2.mp3","dialects":["British English"],"phoneticNotation":"IPA","phoneticSpelling":"ˈɛːrəpleɪn"}],"text":"aeroplane"}],
"type":"headword","word":"aeroplane"
}
Modify these lines :
String lexicalEntries = results.getJSONObject(0).getString("lexicalEntries");
definitionView.setText(lexicalEntries);
to :
String definition = results.getJSONObject(0).getString("lexicalEntries")
.getJSONArray("entries").getJSONObject(0).getJSONArray("senses")
.getJSONObject(0).getJSONArray("definitions").getString(0);
definitionView.setText(definition);
Of course you may need to modify your UI based on the number of definitions a word has.
Also, you should probably consider using POJOs instead of directly dealing with the JSON response.
I'd recommend Jackson or GSON for doing this.
String definitions=results.getJSONArray("lexicalEntries")
.getJSONObject(0)
.getJSONArray("entries")
.getJSONObject(0)
.getJSONArray("senses")
.getJSONArray("definitions")
.get(0)
So , The thing is , There are a lot of gaps in the JSON for different words .
Which means a word may have an array of "synonyms" but others don't , So in your code you are trying to reach something that doesn't actually exist (a NULL value) which is likely to throw an exception every time you search for a word that the JSON returned doesn't match the JSON you are expecting , Because there are missing (NULL) values .
The app I made using oxford dictionary required a lot of work just to make sure there is no thrown exception .
I used retrofit with moshi converter factory , And then Do the following :
1-In your custom classes , Make sure you annotate every data member with
#Json and provide the name of the keys in the JSON of oxford
2-make sure that every declared type is nullable , including both List and the type inside of it
You'll then be able to get the result , And Now comes the part where you handle evey call that may be null
I know this is a bit old question , But It happened that I struggled with this api once , So I hope this may help someone :)

how to get instagram profile picture

in my app use want to put instagram profile pic in his account
how can I get the Profile Picture of a user from Instagram Programmatically
such as :
Using the Instagram API users endpoint (https://api.instagram.com/v1/users/{user-id}/?access_token=ACCESS-TOKEN
) you will receive a response like this one:
{
"data": {
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
"bio": "This is my bio",
"website": "http://snoopdogg.com",
"counts": {
"media": 1320,
"follows": 420,
"followed_by": 3410
}
}
You can then take the profile_picture and download it using some like Facebook Fresco which will then display the image for you.
Well if you actually want the user to POST a instagram profile picture from your app you can't, instagram hasn't provided the post method for posting photos but yes you can get view and download as per the husky's answer.
Follow these steps to get profile pic in your app
Make a request to below link with username and receive the JSON data.
https://apinsta.herokuapp.com/u/USERNAME
Now parse the id of user from the data.
Now visit this link with the ID
https://i.instagram.com/api/v1/users/ID_HERE/info/
Now parse url key in hd_profile_pic_url_info object.
Load the image in ImageView using Glide.
Happy coding !
Credit to Chrisby for his server.
https://stackoverflow.com/a/49862390/9565955
Actually I'm using a method that doesn't require an Access Token the only thing your need is an username. I'll leave you the code down bellow
Step 1: MainActivity.java
Add this code in to your main activity, create a String function to named getHDProfilePicFromUsername the fuction should look like this:
///This function will return to you the url of the user profile picture
private String getHDProfilePicFromUsername(String username) throws ExecutionException, InterruptedException, JSONException {
JSONObject jObject;
String profileInfo = new getDataFromUrl(MainActivity.this).execute("https://www.instagram.com/"+username+"/?__a=1").get();
jObject= new JSONObject(profileInfo);
jObject = jObject.getJSONObject("graphql");
jObject = jObject.getJSONObject("user");
String response = jObject.getString("profile_pic_url_hd");
return response;
}
Then create an internal class inside your Activity named getDataFromUrl, the class should look like this:
private class getDataFromUrl extends AsyncTask<String, Void, String> {
Context mContext;
public getDataFromUrl(Context mContext) {
this.mContext = mContext;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected String doInBackground(String... arg0) {
HttpHandler sh = new HttpHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(arg0[0]);
Log.e(TAG, "Response from url: " + jsonStr);
if (jsonStr != null) {
return jsonStr;
} else {
Log.e(TAG, "Couldn't get json from server.");
return null;
}
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
String url = s.replace('|',',').split(",")[1];
Log.d(TAG, "Link: " + url);
}
}
Now you are able to get an user profile picture URL, as a bonus I'll let you the code for using that URL and get the picture in to an ImageView.
Step 2: main_activity.xml
Add an image view, the ImageView, can be custom but I recommend 1:1 scale to keep image quality. Your xml should look like this:
<ImageView
android:id="#+id/imgProfilePic"
android:scaleType="fitXY"
android:src="#drawable/ic_image_black_24dp"
android:layout_width="300dp"
android:layout_height="300dp"/>
</RelativeLayout>
Step 3: DownloadImageTask.java
Now you need to create an external class called DownloadImageTask the full code have to be like this one:
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;
import java.io.InputStream;
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
Step 4: MainActivity.java
Now the last step will be to add your Main Activity the piece of code to load the ImageView, this code will be in your OnCreate void inside your MainActivity.java
ImageView = thumbnails = (ImageView)findItemById(R.id.imgProfilePic);
new DownloadImageTask(thumbnails).execute(getHDProfilePicFromUsername("jusnjshb"));
That's all, hope it helps I have 2 years using this code hope it helps.

How to convert image string from Firebase Database to bitmap in Android?

I am trying to retrieve photo url from Firebase and convert it to bitmap. Uploading to Firebase and retrieving images from Firebase storage to show in listview is no problem because Glide library is converting the url and placing the image into an ImageView. For a bitmap texture in OpenGL though, Glide isn't appropriate. The photo url comes out like this (key information has been altered to preserve security but the format is the same):
https://firebasestorage.googleapis.com/v0/b/api-project-123456789000.appspot.com/o/jzL123yO1ZxTZ1Se4ldYk2YD92v1%2Ffull%2F1234572738682%2Fcropped.jpg?alt=media&token=1e6cad76-1234f-4f9d-8923-7af07015da7d
In the logcat it shows the retrieved url. In that format though. I save the url to with SharedPreferences. I am using the Rajawali OpenGL framework to show a 3d model which gets it's bitmap from the image url that was saved to SharedPreferences. I use this async class to convert the url to bitmap and apply it to the 3d models texture.
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import org.rajawali3d.materials.textures.Texture;
import org.rajawali3d.materials.textures.TextureManager;
public class AsyncLoadImageTask extends AsyncTask<String, String, Bitmap> {
private final static String TAG = "AsyncTaskLoadImage";
private Texture texture;
public AsyncLoadImageTask(Texture texture) {
this.texture = texture;
}
#Override
protected Bitmap doInBackground(String... params) {
Bitmap bitmap = null;
try {
URL url = new URL(params[0]);
bitmap = BitmapFactory.decodeStream((InputStream)url.getContent());
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
return bitmap;
}
#Override
protected void onPostExecute(Bitmap bitmap) {
texture.setBitmap(bitmap);
TextureManager.getInstance().replaceTexture(texture);
}
}
I then call this in my renderers onRender() method:
try {
//This is reference to the String containing the url
String url = UserPrefs.getCustomLabel(mContext);
new AsyncLoadImageTask(labelTex).execute(url);
} catch (Exception e) {
e.printStackTrace();
}
}
When the Rajawali framework tries to apply the converted bitmap, it says that the url string is null/empty.
This is the referenced method from UserPrefs.getCustomLabel():
public static String getCustomLabel(Context context){
SharedPreferences settings;
String text;
settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); //1
text = settings.getString(LABEL_KEY, null); //2
Log.d(UP_TAG, "Retrieved Url: " + text);
return text;
}
There is a very good chance that Rajawali is making an unauthenticated request to Firebase Storage. If you use the default security rules, that unauthenticated request will be denied.
The common solution is to use a so-called download URL to retrieve the image. A download URL is a publicly accessible, but unguessable, URL. You can get such URL from a Firebase Storage URL by using this code snippet from the Firebase documentation on downloading files:
storageRef.child("users/me/profile.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception exception) {
// Handle any errors
}
});

Android Volley display SVG image

In my Android App I download text-content from my website and store it in my mysql database. Now I want to download and cache images from the same website. With AndroidVolley's <com.android.volley.toolbox.NetworkImageView, downloading normal pictures works pretty good. But I want to download SVG-vector images, cache them and display in my App. So far this is not possible in Android Volley...
I already tried to download the SVGs with AndroidVolley as a String and then put them in a svg-android element (See here), but svg-android did never show my image. It seems, that it can't display SVGs created by Inkscape...
Does anybody know a simple way, how to download these files and display them in a view?
Thanks
// UPDATE 27.3.2015 //
So this is my solution:
With Android Volley I set a StringRequest to access my SVG-Image as a String. The AndroidSVG library (don't mix up with the svg-android library) may convert this String into a SVG-Object and put it into an SVGImageView-View. Here is an example Code how it worked:
StringRequest stringRequest = new StringRequest("http://******/image.svg",new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
SVG svg = SVG.getFromString(response);
View view = getView();
if(view != null){
SVGImageView target = (SVGImageView)view.findViewById(catID);
target.setSVG(svg);
}
} catch (Exception e) {
e.printStackTrace();
}
}
},new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d(Globals.TAG,"Fehler "+error);
}
});
RequestQueue queue = Volley.newRequestQueue(mContext);
stringRequest.setShouldCache(true);
queue.add(stringRequest);
Thanks a lot!
Here is a slightly different solution because I wanted to store the image loaded in a variable for reuse several times.
So I just changed the source Volley replacing "private" with "protected" for the method
protected Response <Bitmap> doParse (NetworkResponse response)
Then I created a class that inherits from ImageRequest and which uses the AndroidSVG library.
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.widget.ImageView;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.ImageRequest;
import com.caverock.androidsvg.SVG;
import com.caverock.androidsvg.SVGParseException;
/**
* Version modifiée de ImageRequest de Volley pour gérer aussi les images SVG
*/
public class MultiFormatImageRequest extends ImageRequest {
final String TAG = "EE." + getClass().getSimpleName();
boolean isSVG = false;
public MultiFormatImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
ImageView.ScaleType scaleType, Bitmap.Config decodeConfig, Response.ErrorListener errorListener) {
super(url, listener, maxWidth, maxHeight, scaleType, decodeConfig, errorListener);
String extension = url.substring(url.lastIndexOf("."));
isSVG = (extension.toUpperCase().contains("SVG"));
}
/****
* ATTENTION : "private" Response in Volley need to be changed in protected
*/
#Override
protected Response<Bitmap> doParse(NetworkResponse response) {
Bitmap image = null;
if (isSVG) {
try {
SVG svg = SVG.getFromString(new String(response.data));
int h = (int) svg.getDocumentHeight();
int w = (int) svg.getDocumentWidth();
image = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444); // transparent
Canvas bmcanvas = new Canvas(image);
svg.renderToCanvas(bmcanvas);
} catch (SVGParseException ex) {
ex.printStackTrace();
}
if (image == null) {
return Response.error(new ParseError(response));
} else {
return Response.success(image, HttpHeaderParser.parseCacheHeaders(response));
}
} else
return super.doParse(response); // Volley default
}
}
You can try two things:
1. With svg-android library, you need to set
imgView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
to make it work.
2. If the first approach doesn't work, you can try using SVGImageView.

How to read data from a Google spreadsheet for an Android app

I have a public google spreadsheet with some data in tables.
I'm developing an Android app which I want it to read these tables and then make a listview with the fields on the spreadsheet.
Which will be the best way to do that?
You can use the code of James Moore: http://blog.restphone.com/2011/05/very-simple-google-spreadsheet-code.html.
package com.banshee;
import java.io.IOException;
import java.net.URL;
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.CustomElementCollection;
import com.google.gdata.data.spreadsheet.ListEntry;
import com.google.gdata.data.spreadsheet.ListFeed;
import com.google.gdata.util.ServiceException;
public class SpreadsheetSucker {
public static void main(String[] args) {
SpreadsheetService service = new SpreadsheetService("com.banshee");
try {
// Notice that the url ends
// with default/public/values.
// That wasn't obvious (at least to me)
// from the documentation.
String urlString = "https://spreadsheets.google.com/feeds/list/0AsaDhyyXNaFSdDJ2VUxtVGVWN1Yza1loU1RPVVU3OFE/default/public/values";
// turn the string into a URL
URL url = new URL(urlString);
// You could substitute a cell feed here in place of
// the list feed
ListFeed feed = service.getFeed(url, ListFeed.class);
for (ListEntry entry : feed.getEntries()) {
CustomElementCollection elements = entry.getCustomElements();
String name = elements.getValue("name");
System.out.println(name);
String number = elements.getValue("Number");
System.out.println(number);
}
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
}
}
I have developed a client Lib for SpreadSheet which works on Android. Please try-
http://code.google.com/p/google-spreadsheet-lib-android/
hope it helps.
Cheers,
Prasanta

Categories

Resources