在这里,我需要在我的应用程序中使用PDF查看器。我采取了许多API作为参考,但仍然坚持在查看PDF文件从SDCARD。这里我的代码
'第一个.java
public class First extends ListActivity {
String[] pdflist;
File[] imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}}
第二个.java
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;
}}
我用Android-Pdf-Reader-Libraryproject.in我的模拟器对话框作为“加载PDF文件”点击PDF文件后出现。你们谁能告诉我如何通过手指滑动来更改PDF页面?
2条答案
按热度按时间nmpmafwu1#
你可以在谷歌文档上打开pdf
要在应用程序(如quick pdf或adobe pdf reader)中打开PDF:
ax6ht2ek2#
您可以使用AndroidPdfViewer库。
在您的等级中添加此依赖关系:
在activity_main.xml中添加PDF视图
添加在www.example.com中加载PDF文件MainActivity.java
或
或
或
或
或
如果您正在使用ProGuard,请不要忘记添加以下行: