我有两种类型的阅读 第一:从url OnWebView读取Pdf:它的工作原理 第二:Pdf从本地路径读取OnWebView:dosent working
(/ data / data / com.akfix.navigationdrawer / files / 550192f3a1583.pdf)
第二张图表无法正常工作。我没有任何错误记录。我该怎么做,
我的Pdf读者课程在这里;
public class PdfReader extends Activity {
String pdf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pdf_reader);
WebView webview = (WebView) findViewById(R.id.webView3);
Bundle extras = getIntent().getExtras();
if (extras != null) {
pdf = extras.getString("pdfUrl");
if (extras.getString("catalogPdfUrl") != null) {
String pdfPath = extras.getString("catalogPdfUrl");
Uri path = Uri.parse(pdfPath);
viewPdf(path);
} else {
webview.getSettings().setJavaScriptEnabled(true);
pdf.replaceAll("\"", "");
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
}
}
}
private void viewPdf(Uri file) {
Intent intent;
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(file, "application/pdf");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Application Found");
builder.setMessage("Download one from Android Market?");
builder.setPositiveButton("Yes, Please",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent
.setData(Uri
.parse("market://details?id=com.adobe.reader"));
startActivity(marketIntent);
}
});
builder.setNegativeButton("No, Thanks", null);
builder.create().show();
}
}
}
请帮帮我。
答案 0 :(得分:2)
因为它是本地的,为什么你需要在webview中显示它?
我在我的应用中使用了this library,这简直太棒了
加载PDF文件
pdfView.fromAsset(pdfName)
.pages(0, 2, 1, 3, 3, 3)
.defaultPage(1)
.showMinimap(false)
.enableSwipe(true)
.onDraw(onDrawListener)
.onLoad(onLoadCompleteListener)
.onPageChange(onPageChangeListener)
.load();