我尝试使用pdfView库,我添加了pdfviewlibrary jar和everything.But它只显示"加载PDF页面"。我在资产文件夹
中有我的pdf文件任何1请帮我找出解决方案吗? 我在下面提到了我的代码
谢谢
package com.example.pdfviewer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends PdfViewerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
}
public int getPreviousPageImageResource() { return R.drawable.left_arrow; }
public int getNextPageImageResource() { return R.drawable.right_arrow; }
public int getZoomInImageResource() { return R.drawable.zoom_in; }
public int getZoomOutImageResource() { return R.drawable.zoom_out; }
public int getPdfPasswordLayoutResource() { return R.layout.pdf_file_password; }
public int getPdfPageNumberResource() { return R.layout.dialog_pagenumber; }
public int getPdfPasswordEditField() { return R.id.etPassword; }
public int getPdfPasswordOkButton() { return R.id.btOK; }
public int getPdfPasswordExitButton() { return R.id.btExit; }
public int getPdfPageNumberEditField() { return R.id.pagenum_edit; }
}
答案 0 :(得分:0)
我也遇到了同样的问题,但我解决了...... 你给定的代码是正确的,只是检查你正在采取的文件的路径是否正确是没有问题的。在我的项目中,我在这一点上犯了错误,因此可以解决你的问题。供你参考我给你的代码......
private File currentDir;
private FileArrayAdapter file_adapter;
String path;
@SuppressLint("SdCardPath") @Override
public void onClick(View v) {
// TODO Auto-generated method stub
currentDir = new File("/sdcard/");
fill(currentDir);
}
@SuppressLint("SdCardPath") private void fill(File f)
{
File[]dirs = f.listFiles();
Faculty_Notes.this.setTitle("Current Dir: "+f.getName());
List<Option>dir = new ArrayList<Option>();
List<Option>fls = new ArrayList<Option>();
try{
for(File ff: dirs)
{
if(ff.isDirectory())
dir.add(new Option(ff.getName(),"Folder",ff.getAbsolutePath()));
else
{
if(ff.getName().endsWith(".pdf"))
{
fls.add(new Option(ff.getName(),"File Size: "+ff.length(),ff.getAbsolutePath()));
}
}
}
}catch(Exception e)
{
e.printStackTrace();
}
Collections.sort(dir);
Collections.sort(fls);
dir.addAll(fls);
if(!f.getName().equalsIgnoreCase("/sdcard"))
dir.add(0,new Option("..","Parent Directory",f.getParent()));
file_adapter = new FileArrayAdapter(Faculty_Notes.this,R.layout.file_view,dir);
Faculty_Notes.this.setListAdapter(file_adapter);
}
@Override
protected void onListItemClick(ListView lv, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(lv, v, position, id);
Option o = file_adapter.getItem(position);
if(o.getData().equalsIgnoreCase("folder")||o.getData().equalsIgnoreCase("parent directory")){
currentDir = new File(o.getPath());
fill(currentDir);
}
else
{
onFileClick(o);
}
}
private void onFileClick(Option o)
{
path = o.getPath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(Faculty_Notes.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
同样,Second.class文件包含您在上面给出的代码。
希望这会帮助你好运:))