【发布时间】:2015-08-30 14:41:55
【问题描述】:
我想在我的应用程序中打开一个 PDF 文件,但每次都会出错。 是的,我看了很多关于它的话题,但是没有一个对我有帮助。
以下是一些错误照片:
btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//startActivity(new Intent(MainActivity.this, Activity2.class));
File file = null;
file = new File(Environment.getExternalStorageDirectory() + "/raw/" + "tirepressuremonitoringsystem3.pdf");
Toast.makeText(getApplicationContext(), file.toString() , Toast.LENGTH_LONG).show();
if(file.exists()) {
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file), "application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or something
}
}
else
Toast.makeText(getApplicationContext(), "File path is incorrect." , Toast.LENGTH_LONG).show();
}
}
);
也许错误是我将这些文件放在 /raw 中?我应该将它们存储在 asset 文件夹 中吗?
【问题讨论】:
-
这个错误是因为你的路径文件不正确。您将 PDF 文件放在哪里?
-
现在我明白了 -> i.imgur.com/Hi18Be3.jpg
标签: java android pdf android-studio filepath