android - Retrieve data from Google Books Api -
i'm new android , using web apis, , i'm writing android app scans barcode book , search isbn in google books api.
i have url after barcode scan: https://www.googleapis.com/books/v1/volumes?q=isbn:9788432250651&aizasycpyez5556x4uzpv6rf4kkspj9dscs_q_c
and next code:
private class getbookinfo extends asynctask <view, void, integer> { @override protected integer doinbackground(view... urls) { // make call url makecall("https://www.googleapis.com/books/v1/volumes?" + "q=isbn:" + ean_content + "&aizasycpyez5556x4uzpv6rf4kkspj9dscs_q_c"); //print call in console system.out.println("https://www.googleapis.com/books/v1/volumes?" + "q=isbn:" + ean_content + "&aizasycpyez5556x4uzpv6rf4kkspj9dscs_q_c"); return null; } @override protected void onpreexecute() { // can start progress bar here } @override protected void onpostexecute(integer result) { string ruta = save_cover(getapplicationcontext(), title, book_cover); intent intent = new intent(mainactivity.this, spreadsheets.class); // intent.putextra(title,title); // intent.putextra(author,authors); // intent.putextra(date,date); // intent.putextra(category,categories); // intent.putextra(description,description); //finish(); startactivity(intent); finish(); } } public void makecall(string stringurl) { url url = null; bufferedinputstream = null; jsonreader jsonreader; try { url = new url(stringurl); } catch (exception ex) { system.out.println("malformed url"); } try { if (url != null) { httpsurlconnection urlconnection = (httpsurlconnection) url.openconnection(); = new bufferedinputstream(urlconnection.getinputstream()); } } catch (ioexception ioe) { system.out.println("ioexception"); } if (is != null) { try { jsonreader = new jsonreader(new inputstreamreader(is, "utf-8")); jsonreader.beginobject(); while (jsonreader.hasnext()) { string name = jsonreader.nextname(); if (name.equals("title")) { title = jsonreader.nextstring(); } else if (name.equals("authors")) { authors = jsonreader.nextstring(); } else if (name.equals("publisheddate")) { date = jsonreader.nextstring(); } else if (name.equals("categories")) { categories = jsonreader.nextstring(); } else if (name.equals("description")) { description = jsonreader.nextstring(); } // else if (name.equals("averagerating")) { // rating = jsonreader.nextstring(); // } else if (name.equals("thumbnail")) { image = jsonreader.nextstring(); book_cover = download_cover(image); } else { jsonreader.skipvalue(); } } jsonreader.endobject(); } catch (exception e) { system.out.println("exception"); } } }
this isn't retrieving api. appreciate help, thank you!
i think need next request connection api, open connection, using json retrieve data api , use inputstream data stored in array. :implement these methods in class:
private static string makehttprequest(url url) throws ioexception
private static string readfromstream(inputstream inputstream) throws ioexception
private static list extractfeaturefromjson(string booksjson)
public static list featchbookdata(string requesturl)
Comments
Post a Comment