我已经开发了一个使用googleapibook搜索来获取书籍的应用程序。我有一个isbn号。现在我想让我的用户一页一页地阅读这本书。但是我没有找到任何在java或android中阅读书籍的方法或解决方案。
这是我的代码。
package com.project.bookhunt;
import java.net.URL;
import java.util.ArrayList;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.json.JSONArray;
import org.json.JSONObject;
import android.content.Context;
import android.widget.Toast;
public class BookSearchParser
{
Context m_context;
static ArrayList<Book_Item> books= new ArrayList<Book_Item>();
String searchResult;
BookSearchParser(Context c,URL url)
{
try
{
m_context=c;
HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod(url.toString());
int statusCode = client.executeMethod(getMethod);
System.out.println("status Code"+statusCode);
System.out.println(getMethod.getResponseBodyAsString());
searchResult=getMethod.getResponseBodyAsString();
parseJSON(searchResult);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static ArrayList<Book_Item> getBooks()
{
return books;
}
private void parseJSON(String object)
{
try
{
books=new ArrayList<Book_Item>();
JSONObject jSonObject = new JSONObject(object);
if(jSonObject.getInt("totalItems")>0)
{
JSONArray jSonObjectArray = jSonObject.getJSONArray("items");
for(int count = 0; count < jSonObjectArray.length();count++)
{
Book_Item item=new Book_Item();
JSONObject jsonItem = (JSONObject) jSonObjectArray.get(count);
if(jsonItem.has(("id")))
{
item.setId(jsonItem.getString("id"));
}
// else
// {
// item.setId("No Id");
// }
if(jsonItem.has("selfLink"))
{
item.setSelfLink(jsonItem.getString("selfLink"));
}
// else
// {
// item.setSelfLink("No Link Avilable");
// }
if(jsonItem.has("volumeInfo"))
{
JSONObject volumeInfo = (JSONObject)jsonItem.get("volumeInfo");
if(volumeInfo.has("title"))
{
item.setTitle(volumeInfo.getString("title"));
}
// else
// {
// item.setTitle("No Title");
// }
if(volumeInfo.has("subtitle"))
{
item.setSubTitle(volumeInfo.getString("subtitle"));
}
// else
// {
// item.setSubTitle("No SubTitle Avilable");
// }
//
if(volumeInfo.has("authors"))
{
JSONArray Authors = volumeInfo.getJSONArray("authors");
for(int authorCount=0;authorCount<Authors.length();authorCount++)
{
item.setAuthor(Authors.getString(authorCount));
}
}
if(volumeInfo.has("description"))
{
item.setDiscription(volumeInfo.getString("description"));
}
// else
// {
// item.setDiscription("No Description Avilable");
// }
if(volumeInfo.has("averageRating"))
{
item.setRating(volumeInfo.getString("averageRating"));
}
if(volumeInfo.has("industryIdentifiers"))
{
JSONArray isbnArray = volumeInfo.getJSONArray("industryIdentifiers");
for(int isbnCount=0;isbnCount<isbnArray.length();isbnCount++)
{
JSONObject isbn=(JSONObject)isbnArray.get(isbnCount);
if(isbn.getString(("type")).equals("ISBN_10"))
{
item.setIsbn10(isbn.getString("identifier"));
}
if(isbn.getString(("type")).equals("ISBN_13"))
{
item.setIsbn13(isbn.getString("identifier"));
}
}
}
if(volumeInfo.has("categories"))
{
JSONArray categoriesArray = volumeInfo.getJSONArray("categories");
for(int j=0;j<categoriesArray.length();j++)
{
item.setCategory(categoriesArray.getString(j));
}
}
// else
// {
// item.setCategory("No category");
// }
//
if(volumeInfo.has("imageLinks"))
{
JSONObject ImageLinks = volumeInfo.getJSONObject("imageLinks");
if(ImageLinks.has("smallThumbnail"))
{
item.setSmallThumb(ImageLinks.getString("smallThumbnail"));
}
if(ImageLinks.has("thumbnail"))
{
item.setThumb(ImageLinks.getString("thumbnail"));
}
// else
// {
// //item.setSmallThumb("No Thumbnail");
// }
//
if(ImageLinks.has("previewLink"))
{
item.setPreviewLink((ImageLinks.getString("previewLink")));
}
// else
// {
// item.setPreviewLink("No Thumbnail");
// }
}
// else
// {
// //item.setSmallThumb("No Thumbnail");
// item.setPreviewLink("No Preview");
// }
}
books.add(item);//add one volume to array_list
}
}
else
{
Toast.makeText(m_context, "0 Record Found..",Toast.LENGTH_SHORT).show();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}发布于 2011-05-19 19:43:05
这里有一个可能的解决方案。
因为您正在使用图书搜索API,并且能够获取图书的ISBN
然后,为了允许您的用户阅读这本书,可以:
使用带有Google Docs Embedded Viewer API的WebView +您的ISBN,您将能够在该WebView中加载图书预览
例如,具有以下代码的WebView:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Books Embedded Viewer API Example</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("books", "0");
function initialize() {
var viewer = new google.books.DefaultViewer(document.getElementById('viewerCanvas'));
viewer.load('**ISBN:0738531367**');
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<div id="viewerCanvas" style="width: 600px; height: 500px"></div>
</body>
</html>这是我为您提供的解决方案,技巧位于: google.books.DefaultViewer(document.getElementById('viewerCanvas'));viewer.load('ISBN:0738531367');
我希望这对你有帮助
要更好地了解这一点,请访问http://code.google.com/apis/books/docs/viewer/developers_guide.html,网址为嵌入式查看器API的“您好,世界”
当您使用该应用程序接口时,您可以获得类似以下内容的代码:http://code.google.com/apis/books/docs/viewer/examples/book-simple.html
https://stackoverflow.com/questions/6057859
复制相似问题