Android的浏览器没有内置的PDF支持默认所以这个不能轻易与实现。
但是这里有两件事你可以做。
1)下载,并从Play商店安装Adobe Reader,然后尝试下面的代码
首先你在设备内存中创建一个文件,然后你阅读PDF数据进去。 “theurl”是其中的PDF位于
InputStream in = null;
File dst = new File(Environment.getExternalStorageDirectory()+"/myPDF.pdf");
try {
in = theurl.openStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputStream out = null;
try {
out = new FileOutputStream(dst);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
}
// Transfer bytes from in to out
try {
byte[] buf = new byte[100000];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent = new Intent();
Uri path = Uri.fromFile(dst);
intent.setDataAndType(path, "application/pdf");
startActivity(intent);
这将下载的PDF格式,请在设备内存中创建它,然后意图将使用adove读者您的设备上打开它通过应用程序的URL。
另一种选择是
2)进入http://jaspreetchahal.org/android-how-to-open-pdf-file-within-the-browser/,看到那家伙是怎么做的
请回应下面的答案,说它是否对你有帮助 – krilovich