Mohammad Reza Majid Pour Mohammad Reza Majid Pour - 3 months ago 25
Android Question

is it possible to use web view as a html reader (offline)?

i was searching for a way to zoom for both text and picture in my layout.
according to some questions web view is a easy way to do it. after a while i found this code for webview:

import android.os.Bundle;
import android.webkit.WebView;

public class WebViewActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {

webView = (WebView) findViewById(;



i tried to use
instead of

so i used this path:

file:///sdcard/Android/data/[My App Package Name]/about.html

it seems its working fine for me, but i have some serious problems.

here is my problems:

  1. is this path i am using is works for all other android devices?

  2. i dont know how to extract html files for the first run in to that path i am using.

  3. is there anyway to load the files from assets?

  4. what is the source code for extract files in first run?

  5. can i use other formats like pdf or doc instead of html? if i couldnt what should i change in the source code?

thank guys for helping me. should i give up or continue this idea?


You could just put the file into your assets folder in the source code, and then do this:

WebView webView = (WebView)findViewById(;

For display PDF:

Since API Level 21 (Lollipop) Android provides a PdfRenderer class:

// create a new renderer
PdfRenderer renderer = new PdfRenderer(getSeekableFileDescriptor());

// let us just render all pages
final int pageCount = renderer.getPageCount();
for (int i = 0; i < pageCount; i++) {
  Page page = renderer.openPage(i);

  // say we render for showing on the screen
  page.render(mBitmap, null, null, Page.RENDER_MODE_FOR_DISPLAY);

  // do stuff with the bitmap

  // close the page

// close the renderer

This sample demonstrates how to display PDF document on screen using the PdfRenderer introduced in Android 5.0 Lollipop.

For older APIs, checkout AndroidPdfViewer library, works on API 11 and higher:

    .pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default