[英]Open external PDF file on android emulator
我试图打开具有外部链接的PDF文件,但是在打开Adobe Reader之后,它提示我“文档路径无效”
这是我写的代码:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
File file = new File("http://www.kb.nl/sites/default/files/docs/pdf_guidelines.pdf");
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path,"application/pdf");
try
{
startActivity(intent);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(MainActivity.this,
getString(R.string.app_name),
Toast.LENGTH_SHORT).show();
}
}
});
如何在模拟器中打开外部PDF文件,我的目标是打开Google驱动器内部的pdf文件。
提前致谢。
File file = new File("http://www.kb.nl/sites/default/files/docs/pdf_guidelines.pdf");
http://www.kb.nl/sites/default/files/docs/pdf_guidelines.pdf不是File
的路径。 它是网站的URL。 您不能将Web URL包装在File
对象中并期望它起作用。
您可以尝试使用Uri.parse("http://www.kb.nl/sites/default/files/docs/pdf_guidelines.pdf")
来获取您的Uri
并查看Adobe Reader是否支持它,但是我对此表示怀疑。
您更有可能需要自己下载PDF,然后在Intent
使用该 File
。
这几行魔术:
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("Url to pdf or other")));
} catch (ActivityNotFoundException e) {
//do something here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.