Epub格式讀法
發表人:
訪客
小弟最近在寫一個作業
要在Android上讀EPUB格式的電子書
但對Android和EPUB都不太熟
只知道EPUB格式是HTML
但不知道要如何用Andorid去寫讀EPUB的程式
不知道是否有範例參考
麻煩一下了
要在Android上讀EPUB格式的電子書
但對Android和EPUB都不太熟
只知道EPUB格式是HTML
但不知道要如何用Andorid去寫讀EPUB的程式
不知道是否有範例參考
麻煩一下了
發表人:
Seachaos
積分: 2432
積分: 2432
[quote]訪客 提到:
小弟最近在寫一個作業
要在Android上讀EPUB格式的電子書
但對Android和EPUB都不太熟
只知道...[/quote]
您好,我這有找到一個Open Source的Android SDK可以參考看看
http://www.siegmann.nl/epublib/android
有問題的話歡迎一起研究 :)
小弟最近在寫一個作業
要在Android上讀EPUB格式的電子書
但對Android和EPUB都不太熟
只知道...[/quote]
您好,我這有找到一個Open Source的Android SDK可以參考看看
http://www.siegmann.nl/epublib/android
有問題的話歡迎一起研究 :)
發表人:
nobb
積分: 58
積分: 58
看了半天沒有頭緒...
有夠複雜的!
他的EpubReader,Book是自己寫的類別?
照步驟做還是沒法DEBUG...好煩啊!!
有夠複雜的!
他的EpubReader,Book是自己寫的類別?
照步驟做還是沒法DEBUG...好煩啊!!
發表人:
Seachaos
積分: 2432
積分: 2432
是的,這是第三方的Libary
不知道你是想做到怎樣的效果呢?
不知道你是想做到怎樣的效果呢?
發表人:
nobb
積分: 58
積分: 58
我的程式內容:
1.登入畫面
2.Tabhost(3個分頁[1]地圖[2]EpubReader[3]商店(類Android Market)
3.選到第2分頁能夠選Epub格式讀取
我一直在找Source code,找了很多但都不能執行!
可以幫助我一下嗎,感謝!
1.登入畫面
2.Tabhost(3個分頁[1]地圖[2]EpubReader[3]商店(類Android Market)
3.選到第2分頁能夠選Epub格式讀取
我一直在找Source code,找了很多但都不能執行!
可以幫助我一下嗎,感謝!
發表人:
Seachaos
積分: 2432
積分: 2432
Hi,上面提到的
http://www.siegmann.nl/epublib/android
是可以執行的
但你要加兩個Libary
1. epublib-core
2. slf4j-android
然後照他的範例就可以了
[sea:javaCode]
EpubReader eread = new EpubReader();
InputStream epubInputStream = getResources().openRawResource(R.raw.test); // 從Raw中取得test.epub
// Load Book from inputStream
Book book = eread.readEpub(epubInputStream);
// Log the book's authors
book.getMetadata().getAuthors(); //作著
// Log the book's title
book.getTitle(); //標題
// Log the book's coverimage property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
.getInputStream()); //取得封面圖片
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(coverImage); // 顯示epub的封面
[/sea]
http://www.siegmann.nl/epublib/android
是可以執行的
但你要加兩個Libary
1. epublib-core
2. slf4j-android
然後照他的範例就可以了
[sea:javaCode]
EpubReader eread = new EpubReader();
InputStream epubInputStream = getResources().openRawResource(R.raw.test); // 從Raw中取得test.epub
// Load Book from inputStream
Book book = eread.readEpub(epubInputStream);
// Log the book's authors
book.getMetadata().getAuthors(); //作著
// Log the book's title
book.getTitle(); //標題
// Log the book's coverimage property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
.getInputStream()); //取得封面圖片
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(coverImage); // 顯示epub的封面
[/sea]
發表人:
nobb
積分: 58
積分: 58
那我如果要讀一本電子書,是不是把電子書放在raw底下(res/raw/XXX.epub
然後在
InputStream epubInputStream = getResources().openRawResource(R.raw.test); 的R.raw.(電子書名稱)
然後在
InputStream epubInputStream = getResources().openRawResource(R.raw.test); 的R.raw.(電子書名稱)
發表人:
nobb
積分: 58
積分: 58
[sea:javaCode]
package bbbbb.bbbbb;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.domain.TOCReference;
import nl.siegmann.epublib.epub.EpubReader;
import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
/**
* Log the info of 'assets/books/testbook.epub'.
*
* @author paul.siegmann
*
*/
public class BbbbbbbbbbbActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AssetManager assetManager = getAssets();
try {
// find InputStream for book
InputStream epubInputStream = assetManager
.open("book/435.epub");
// Load Book from inputStream
Book book = (new EpubReader()).readEpub(epubInputStream);
// Log the book's authors
Log.i("epublib", "author(s): " + book.getMetadata().getAuthors());
// Log the book's title
Log.i("epublib", "title: " + book.getTitle());
// Log the book's coverimage property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
.getInputStream());
Log.i("epublib", "Coverimage is " + coverImage.getWidth() + " by "
+ coverImage.getHeight() + " pixels");
// Log the tale of contents
logTableOfContents(book.getTableOfContents().getTocReferences(), 0);
} catch (IOException e) {
Log.e("epublib", e.getMessage());
}
}
/**
* Recursively Log the Table of Contents
*
* @param tocReferences
* @param depth
*/
private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
if (tocReferences == null) {
return;
}
for (TOCReference tocReference : tocReferences) {
StringBuilder tocString = new StringBuilder();
for (int i = 0; i < depth; i++) {
tocString.append("\t");
}
tocString.append(tocReference.getTitle());
Log.i("epublib", tocString.toString());
logTableOfContents(tocReference.getChildren(), depth + 1);
}
}
}
[/sea]
我執行在模擬器時他有錯誤
{
The application XXX(process xxx.xxx) has stopped unexpectedly. Please try again.
}
是我哪個地方沒設定好嗎?
package bbbbb.bbbbb;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.domain.TOCReference;
import nl.siegmann.epublib.epub.EpubReader;
import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
/**
* Log the info of 'assets/books/testbook.epub'.
*
* @author paul.siegmann
*
*/
public class BbbbbbbbbbbActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AssetManager assetManager = getAssets();
try {
// find InputStream for book
InputStream epubInputStream = assetManager
.open("book/435.epub");
// Load Book from inputStream
Book book = (new EpubReader()).readEpub(epubInputStream);
// Log the book's authors
Log.i("epublib", "author(s): " + book.getMetadata().getAuthors());
// Log the book's title
Log.i("epublib", "title: " + book.getTitle());
// Log the book's coverimage property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
.getInputStream());
Log.i("epublib", "Coverimage is " + coverImage.getWidth() + " by "
+ coverImage.getHeight() + " pixels");
// Log the tale of contents
logTableOfContents(book.getTableOfContents().getTocReferences(), 0);
} catch (IOException e) {
Log.e("epublib", e.getMessage());
}
}
/**
* Recursively Log the Table of Contents
*
* @param tocReferences
* @param depth
*/
private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
if (tocReferences == null) {
return;
}
for (TOCReference tocReference : tocReferences) {
StringBuilder tocString = new StringBuilder();
for (int i = 0; i < depth; i++) {
tocString.append("\t");
}
tocString.append(tocReference.getTitle());
Log.i("epublib", tocString.toString());
logTableOfContents(tocReference.getChildren(), depth + 1);
}
}
}
[/sea]
我執行在模擬器時他有錯誤
{
The application XXX(process xxx.xxx) has stopped unexpectedly. Please try again.
}
是我哪個地方沒設定好嗎?
發表人:
Seachaos
積分: 2432
積分: 2432
你好:
slf4j-android這個Libary你有加入嗎?
因為這個Libary其實是要兩個Libary的
epublib-core <- 只有這個的話可以Compile,但執行會錯
slf4j-android <- 執行會用到
slf4j-android這個Libary你有加入嗎?
因為這個Libary其實是要兩個Libary的
epublib-core <- 只有這個的話可以Compile,但執行會錯
slf4j-android <- 執行會用到
發表人:
nobb
積分: 58
積分: 58
我兩個都有加入了,但他compile錯誤
還是模擬器有差啊,我是用2.2的去跑
by the way,版大可以PO一下他在run的圖片給我看一下嗎!
還是模擬器有差啊,我是用2.2的去跑
by the way,版大可以PO一下他在run的圖片給我看一下嗎!
發表人:
nobb
積分: 58
積分: 58
如果可以的話,麻煩版大能把步驟拍成影片or圖片讓我學!!(因為我都用不成功...)
成果展時間不遠了,好緊迫!
成果展時間不遠了,好緊迫!
發表人:
Seachaos
積分: 2432
積分: 2432
這邊是我讀EPub封面圖片的方法
[sea:javaCode]
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("msg","Start Read EPUB");
// AssetManager assetManager = getAssets();
try {
// find InputStream for book
EpubReader eread = new EpubReader();
InputStream epubInputStream = getResources().openRawResource(R.raw.test); // 從Raw中取得test.epub
Log.i("msg","Get InputStream Success");
// Load Book from inputStream
Book book = eread.readEpub(epubInputStream);
Log.i("msg","Read Success");
// Log the book's authors
Log.i("msg", "author(s): " + book.getMetadata().getAuthors());
// Log the book's title
Log.i("msg", "title: " + book.getTitle());
// Log the book's coverimage property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
.getInputStream());
Log.i("msg", "Coverimage is " + coverImage.getWidth() + " by "
+ coverImage.getHeight() + " pixels");
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(coverImage);
// Log the tale of contents
logTableOfContents(book.getTableOfContents().getTocReferences(), 0);
} catch (IOException e) {
Log.e("epublib", e.getMessage());
}
}
/**
* Recursively Log the Table of Contents
*
* @param tocReferences
* @param depth
*/
private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
if (tocReferences == null) {
return;
}
for (TOCReference tocReference : tocReferences) {
StringBuilder tocString = new StringBuilder();
for (int i = 0; i < depth; i++) {
tocString.append("\t");
}
tocString.append(tocReference.getTitle());
Log.i("msg", tocString.toString());
logTableOfContents(tocReference.getChildren(), depth + 1);
}
}
[/sea]
附上我的Main.xml
[sea:javaCode]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView"
/>
</LinearLayout>
[/sea]
[sea:javaCode]
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("msg","Start Read EPUB");
// AssetManager assetManager = getAssets();
try {
// find InputStream for book
EpubReader eread = new EpubReader();
InputStream epubInputStream = getResources().openRawResource(R.raw.test); // 從Raw中取得test.epub
Log.i("msg","Get InputStream Success");
// Load Book from inputStream
Book book = eread.readEpub(epubInputStream);
Log.i("msg","Read Success");
// Log the book's authors
Log.i("msg", "author(s): " + book.getMetadata().getAuthors());
// Log the book's title
Log.i("msg", "title: " + book.getTitle());
// Log the book's coverimage property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
.getInputStream());
Log.i("msg", "Coverimage is " + coverImage.getWidth() + " by "
+ coverImage.getHeight() + " pixels");
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(coverImage);
// Log the tale of contents
logTableOfContents(book.getTableOfContents().getTocReferences(), 0);
} catch (IOException e) {
Log.e("epublib", e.getMessage());
}
}
/**
* Recursively Log the Table of Contents
*
* @param tocReferences
* @param depth
*/
private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
if (tocReferences == null) {
return;
}
for (TOCReference tocReference : tocReferences) {
StringBuilder tocString = new StringBuilder();
for (int i = 0; i < depth; i++) {
tocString.append("\t");
}
tocString.append(tocReference.getTitle());
Log.i("msg", tocString.toString());
logTableOfContents(tocReference.getChildren(), depth + 1);
}
}
[/sea]
附上我的Main.xml
[sea:javaCode]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView"
/>
</LinearLayout>
[/sea]
發表人:
nobb
積分: 58
積分: 58
我這邊還是無法run出來結果...
發表人:
Seachaos
積分: 2432
積分: 2432
發表人:
nobb
積分: 58
積分: 58
我新增的jar
epublib-core-latest.jar - C:\Users\imd\Desktop\Android\epubTest
slf4j-android-1.6.1-RC1-sources.jar - C:\Users\imd\Desktop
我後面的都是路徑呢
epublib-core-latest.jar - C:\Users\imd\Desktop\Android\epubTest
slf4j-android-1.6.1-RC1-sources.jar - C:\Users\imd\Desktop
我後面的都是路徑呢
發表人:
Seachaos
積分: 2432
積分: 2432
路徑不是問題
你的Android版本和模擬器都是Android 2.2以上的嗎?
另外有錯誤的詳細資訊嗎?
你的Android版本和模擬器都是Android 2.2以上的嗎?
另外有錯誤的詳細資訊嗎?
發表人:
nobb
積分: 58
積分: 58
我android版本是選2.2
模擬器也是用2.2的
他就顯示
Sorry!
The application Bbbbbbbb process bbbbb.bbbbb hasstopped unexpectedly. Please try agian.
模擬器也是用2.2的
他就顯示
Sorry!
The application Bbbbbbbb process bbbbb.bbbbb hasstopped unexpectedly. Please try agian.
發表人:
Seachaos
積分: 2432
積分: 2432
嗯…
你的AndroidManifest.xml方便貼出來看看嗎?
你的AndroidManifest.xml方便貼出來看看嗎?
發表人:
nobb
積分: 58
積分: 58
[sea:javaCode]
package test.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.domain.TOCReference;
import nl.siegmann.epublib.epub.EpubReader;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
public class TestagainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("msg","Start Read EPUB");
// AssetManager assetManager = getAssets();
try {
// find InputStream for book
EpubReader eread = new EpubReader();
InputStream epubInputStream = getResources().openRawResource(R.raw.test); // 從Raw中取得test.epub
Log.i("msg","Get InputStream Success");
// Load Book from inputStream
Book book = eread.readEpub(epubInputStream);
Log.i("msg","Read Success");
// Log the book's authors
Log.i("msg", "author(s): " + book.getMetadata().getAuthors());
// Log the book's title
Log.i("msg", "title: " + book.getTitle());
// Log the book's coverimage property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
.getInputStream());
Log.i("msg", "Coverimage is " + coverImage.getWidth() + " by "
+ coverImage.getHeight() + " pixels");
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(coverImage);
// Log the tale of contents
logTableOfContents(book.getTableOfContents().getTocReferences(), 0);
} catch (IOException e) {
Log.e("epublib", e.getMessage());
}
}
/**
* Recursively Log the Table of Contents
*
* @param tocReferences
* @param depth
*/
private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
if (tocReferences == null) {
return;
}
for (TOCReference tocReference : tocReferences) {
StringBuilder tocString = new StringBuilder();
for (int i = 0; i < depth; i++) {
tocString.append("\t");
}
tocString.append(tocReference.getTitle());
Log.i("msg", tocString.toString());
logTableOfContents(tocReference.getChildren(), depth + 1);
}
}
}
[/sea]
我在
InputStream epubInputStream = getResources().openRawResource(R.raw.test); // 從Raw中取得test.epub
的(R.raw.test) raw是有錯誤的...
[sea:javaCode]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestagainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
[/sea]
這是我的AndroidManifest.Xml
package test.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.domain.TOCReference;
import nl.siegmann.epublib.epub.EpubReader;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
public class TestagainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("msg","Start Read EPUB");
// AssetManager assetManager = getAssets();
try {
// find InputStream for book
EpubReader eread = new EpubReader();
InputStream epubInputStream = getResources().openRawResource(R.raw.test); // 從Raw中取得test.epub
Log.i("msg","Get InputStream Success");
// Load Book from inputStream
Book book = eread.readEpub(epubInputStream);
Log.i("msg","Read Success");
// Log the book's authors
Log.i("msg", "author(s): " + book.getMetadata().getAuthors());
// Log the book's title
Log.i("msg", "title: " + book.getTitle());
// Log the book's coverimage property
Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
.getInputStream());
Log.i("msg", "Coverimage is " + coverImage.getWidth() + " by "
+ coverImage.getHeight() + " pixels");
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(coverImage);
// Log the tale of contents
logTableOfContents(book.getTableOfContents().getTocReferences(), 0);
} catch (IOException e) {
Log.e("epublib", e.getMessage());
}
}
/**
* Recursively Log the Table of Contents
*
* @param tocReferences
* @param depth
*/
private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
if (tocReferences == null) {
return;
}
for (TOCReference tocReference : tocReferences) {
StringBuilder tocString = new StringBuilder();
for (int i = 0; i < depth; i++) {
tocString.append("\t");
}
tocString.append(tocReference.getTitle());
Log.i("msg", tocString.toString());
logTableOfContents(tocReference.getChildren(), depth + 1);
}
}
}
[/sea]
我在
InputStream epubInputStream = getResources().openRawResource(R.raw.test); // 從Raw中取得test.epub
的(R.raw.test) raw是有錯誤的...
[sea:javaCode]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestagainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
[/sea]
這是我的AndroidManifest.Xml
發表人:
nobb
積分: 58
積分: 58
真感激版大無私的教導我這noob
有機會想認識認識版大
有機會想認識認識版大