我正在尝试创建一个应用程序,让您查看存储的PDF,就像简单的文件阅读器一样。在Android应用程序中查看本地PDF文件
我正在使用导航抽屉项目基地,我似乎无法打开PDF。
我在assets /中存储了一个测试PDF,而且我也尝试过raw /。如果我尝试使用资产/每当我尝试在设备上打开PDF时崩溃,说“不能显示PDF(test.pdf无法打开)。”
我已经尝试了几种方法来尝试获取此工作但都没有盛行,这里是我的代码截至目前:。
public void onSectionAttached(int number){
switch (number) {
case 1:
mTitle = getString(R.string.title_song);
File pdfFile = new File("/assets/test.pdf");
Uri path = Uri.fromFile(pdfFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(intent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(MainActivity.this, "It didn't crash!", Toast.LENGTH_LONG).show();
}
break;
case 2:
mTitle = getString(R.string.title_artist);
break;
}
}
[Display PDF内的应用程序在Android?](http://stackoverflow.com/questions/2456344/display-pdf-within-app-on-android) –