gpt4 book ai didi

android - 每三个应用程序从嵌入式文件中读取 android 上的 pdf

转载 作者:行者123 更新时间:2023-11-29 02:04:07 25 4
gpt4 key购买 nike

例如,我很难在 adobe 上阅读我的 pdf。我有 Document Viewer,它似乎在我购买之前已经安装在我的手机上(我认为它是默认的 android 应用程序)。有了它,我的代码工作正常。但我见过崩溃,可能是那些没有文档查看器的人。

所以我用 adobe reader 测试了我的代码,它崩溃了!

谁能解释一下我的代码有什么问题(和/或)给我 Gplay 链接让我的用户下载它。

public Intent readPdf(String name, int res) {
final String extStorageDirectory = Environment
.getExternalStorageDirectory().toString();
final String festivalDirectory_path = extStorageDirectory
+ Constants.PDF_STORAGE_PATH;
File pdfOutputFile = new File(festivalDirectory_path, "/");
if (pdfOutputFile.exists() == false) {
pdfOutputFile.mkdirs();
}
File pdfFile = new File(pdfOutputFile, name);
// AssetManager assetManager = getAssets();
InputStream in = null;
try {
// InputStream in = assetManager
// .open("cartecannesplus01pdf.pdf");
in = getResources().openRawResource(res);

OutputStream out = new FileOutputStream(pdfFile);
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ((bufferLength = in.read(buffer)) > 0) {
out.write(buffer, 0, bufferLength);
}
out.flush();
out.close();
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
Uri path = Uri.fromFile(pdfFile);


Intent intent = null;
if (Utils.appInstalledOrNot(me, "com.adobe.reader")) {
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else {
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.adobe.reader"));
}

return intent;

}

谢谢!

雷诺

最佳答案

我发现了问题:参数中的名称必须以 .pdf 结尾

如果不是,则 adobe reader 无法阅读 pdf,但它可以与我尝试过的所有其他 pdf 阅读器一起使用!

谢谢大家!

关于android - 每三个应用程序从嵌入式文件中读取 android 上的 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10977531/

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