我正在嘗試創建一個應用程序,讓您查看存儲的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) –