android pdf查看器库无法正常工作

时间:2014-06-28 16:30:57

标签: java android pdf

我尝试使用android pdf库。从https://github.com/jblough/Android-Pdf-Viewer-Library下载。 现在,当我打开pdf时,它被卡住..说pdf页面正在加载。没有任何反应。

这是我想要做的。 我创建了一个名为qbchem.java和second.java的类文件 我已经在我的资产文件夹中加载了pdf文件。我不希望任何人访问这些pdf文件,这就是为什么我将它们保存在我的资产文件夹中。

  

qbchem.java

@
package com.sp.wisdomedutech11;

import java.io.File;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment; 
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.os.Build;
import net.sf.andpdf.pdfviewer.PdfViewerActivity;


public class qbchem extends Activity {
ListView qbchemlv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.qbchem);
    qbchemlv = (ListView) findViewById(R.id.qbchemlv1);
    String[] values = new String[] { "Chap-1 Basic Concepts", 
            "Chap-2 Atomic Structure",
            "Chap-3 Chemical Bonding",
            "Chap-4 Periodic Table"
           };
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
              android.R.layout.simple_list_item_1, android.R.id.text1, values);
     qbchemlv.setAdapter(adapter); 
     qbchemlv.setOnItemClickListener(new OnItemClickListener() {

         @Override
         public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {

          // ListView Clicked item index
          int itemPosition     = position;

          // ListView Clicked item value
          String  itemValue    = (String) qbchemlv.getItemAtPosition(position);
          if(itemValue.contentEquals("Chap-1 Basic Concepts")){
              try {
                  Intent intent = new Intent(qbchem.this, second.class);
                     intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "file:///android_asset/chap_1_basic_concept.pdf");
                     startActivity(intent);

                } catch (Exception e) {
                    e.printStackTrace();
                }
}

     }
});

}}
  

second.java

package com.sp.wisdomedutech11;

import java.io.File;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.os.Build;
import net.sf.andpdf.pdfviewer.PdfViewerActivity;


public class second extends PdfViewerActivity {

@Override
public int getPreviousPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.left_arrow;
}

@Override
public int getNextPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.right_arrow;
}

@Override
public int getZoomInImageResource() {
// TODO Auto-generated method stub
 return R.drawable.zoom_in;
}

@Override
public int getZoomOutImageResource() {
  // TODO Auto-generated method stub
  return R.drawable.zoom_out;
}

@Override
public int getPdfPasswordLayoutResource() {
// TODO Auto-generated method stub
return R.layout.pdf_file_password;  
}

@Override
public int getPdfPageNumberResource() {
// TODO Auto-generated method stub
 return R.layout.dialog_pagenumber;
}

@Override
public int getPdfPasswordEditField() {
// TODO Auto-generated method stub
return R.id.etPassword;
}

@Override
public int getPdfPasswordOkButton() {
// TODO Auto-generated method stub
 return R.id.btOK;
}

@Override
public int getPdfPasswordExitButton() {
// TODO Auto-generated method stub
 return R.id.btExit;
}

@Override
public int getPdfPageNumberEditField() {
// TODO Auto-generated method stub
return R.id.pagenum_edit;
}}

1 个答案:

答案 0 :(得分:0)

我在尝试获取pdf阅读器时遇到了类似的问题。在您的特定情况下,您无法从资产中获得PDF格式的直接位置。 (可能)唯一可行的做法是将此资产复制到其他位置,然后使用'file:///'。

这可能会帮助您复制文件: Copying a file from withing a apk to the internal storage

看到这个也是为了复制: https://stackoverflow.com/a/19555787/2670775