我想在android模拟器中从url读取pdf文件。
我已完成以下操作,但无效
WebView web1 =(WebView)findViewById(R.id.webview);
web1.getSettings().setJavaScriptEnabled(true);
web1.loadUrl("http://docs.google.com/viewer?url=http%3A%2F%2Fwww.cranialtech.com%2Fimages%2Fstories%2FFiles%2Fpositioningprotocol.pdf");
和
Uri path = Uri.parse("http://docs.google.com/viewer?url=http%3A%2F%2Fwww.cranialtech.com%2Fimages%2Fstories%2FFiles%2Fpositioningprotocol.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf"); //Set data type
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(intent);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(this," pdf not found",
Toast.LENGTH_SHORT).show();
}
但它仍无效。
请帮帮我
提前感谢。
答案 0 :(得分:1)
试试这段代码::
WebView web1 =(WebView)findViewById(R.id.webview);
web1.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://docs.google.com/viewer?url=http%3A%2F%2Fwww.cranialtech.com%2Fimages%2Fstories%2FFiles%2Fpositioningprotocol.pdf");