gpt4 book ai didi

java - PDF文件路径不正确

转载 作者:行者123 更新时间:2023-11-30 02:04:52 24 4
gpt4 key购买 nike

<分区>

我想在我的应用程序中打开一个 PDF 文件,但每次都会出错。是的,我看了很多关于它的话题,但是没有一个对我有帮助。

以下是错误的一些照片:

http://i.stack.imgur.com/TZpO2.jpg

http://i.stack.imgur.com/CuoeM.jpg

 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 中?我应该将它们存储在 assest 文件夹中吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com