有人可以确认 adobe reader 可以与自定义内容提供商合作吗
我已经实现了一个自定义内容提供程序,将 pdf 文档作为 ParcelFileDescriptor 提供服务。文件存储在标记为“私有”的本地存储中。然后,根据 URI,将文档移交给选定的 pdf 应用程序。
这适用于除 adobe reader 之外的所有 PDF 查看器应用程序。有人可以确认 adobe reader 不能与内容提供商合作吗?代码如下:
下载文档后:
private void loadDocInReader(String doc) throws ActivityNotFoundException, Exception
{
Uri uri = Uri.parse(doc);
logger.debug("PDF Application ID is: " + pdfAppID);
if (this.pdfAppID != null && this.pdfAppID.length() > 0)
{
boolean pdfApplicationIsInstalled = checkPDFApplicationIsInstalled(this.pdfAppID);
if(pdfApplicationIsInstalled) {
Intent intent = new Intent();
intent.setPackage(pdfAppID);
intent.setData(uri);
intent.setType("application/pdf");
startActivity(intent);
}
else {
logger.error("Please install Adobe Reader first!");
}
}
else {
Intent intent = new Intent();
intent.setData(uri);
intent.setType("application/pdf");
startActivity(intent);
}
}
除了 adobe reader 之外,所有其他 pdf 查看器应用程序都会调用此方法:
public class DocumentProvider extends ContentProvider
{
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException
{
File file = null;
try {
file = new File(uri.getPath());
logger.debug("Delivering ParcelFileDescriptor for path: " + file.getPath());
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
} catch (FileNotFoundException e) {
logger.error("Error loading Document: ",e);
} finally {
if(file.exists()) {
file.delete();
}
}
return null;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}
}
Adobe Reader 总是提示:“无效的文件路径”
提前致谢!凯。
I have implemented a custom content provider serving pdf documents as ParcelFileDescriptor. Files are stored in the local storage marked as PRIVATE. Based on an URI the documents are then handed over to the selected pdf application.
This works for all PDF Viewer applications except adobe reader. Can someone please confirm that adobe reader does not work with content providers? Code below:
When document has been downloaded:
private void loadDocInReader(String doc) throws ActivityNotFoundException, Exception
{
Uri uri = Uri.parse(doc);
logger.debug("PDF Application ID is: " + pdfAppID);
if (this.pdfAppID != null && this.pdfAppID.length() > 0)
{
boolean pdfApplicationIsInstalled = checkPDFApplicationIsInstalled(this.pdfAppID);
if(pdfApplicationIsInstalled) {
Intent intent = new Intent();
intent.setPackage(pdfAppID);
intent.setData(uri);
intent.setType("application/pdf");
startActivity(intent);
}
else {
logger.error("Please install Adobe Reader first!");
}
}
else {
Intent intent = new Intent();
intent.setData(uri);
intent.setType("application/pdf");
startActivity(intent);
}
}
All other pdf viewer apps call this method except adobe reader:
public class DocumentProvider extends ContentProvider
{
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException
{
File file = null;
try {
file = new File(uri.getPath());
logger.debug("Delivering ParcelFileDescriptor for path: " + file.getPath());
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
} catch (FileNotFoundException e) {
logger.error("Error loading Document: ",e);
} finally {
if(file.exists()) {
file.delete();
}
}
return null;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}
}
Adobe Reader always states: "Invalid File Path"
Thanks in advance!!! Kay.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,Adobe Reader 对从 ContentProvider 读取文件的支持不稳定。就我而言,调用 openFile 方法并返回有效的 ParcelFileDescriptor,但 Adobe Reader 报告“无法打开文档”。我的内容提供程序与“Drive PDF Viewer”、“PDF Reader”和“qPDF Reader”配合良好,它们是 Play 商店中的一些顶级 PDF 查看器。
Adobe Reader 能够使用 Gmail 内容提供商打开 Gmail 中的 PDF 文件附件,但我无法确定其工作方式或原因。
As far as I can determine Adobe Reader has flaky support for reading files from ContentProviders. In my case, the openFile method is called and returns a valid ParcelFileDescriptor, but Adobe Reader reports "The document could not be opened." My content provider works fine with "Drive PDF Viewer", "PDF Reader" and "qPDF Reader", which are some of the top PDF viewers in the Play Store.
Adobe Reader is able to open PDF file attachments in Gmail using the Gmail content provider, but I cannot determine how or why that works.
我还遇到 Adobe Acrobat Reader 无法与我的自定义提供程序配合使用的问题,但最终让它正常工作。我的问题是应用程序本地文件空间中的文件被加密并且它们的名称被散列。因此
Uri
类似于:它适用于我测试过的任何 PDF 查看器应用程序(Adobe Reader 除外)。今天,我最后一次尝试向 Content Uri 添加
.pdf
扩展名(这绝对不是必需的),当 Adobe 调用openFile() 函数我去掉了扩展名。瞧,它有效了!!!
更新
请确保您的
ContentProvider
也返回_display_name
列作为query(Uri, String[], String, String[ ], String)
查询还包含.pdf
扩展名!!!注意
使用Adobe Acrobat Reader版本16.3进行测试
I has also issues with Adobe Acrobat Reader not working with my custom provider and finally got it working. My problem was that files in app-local file-space are encrypted and their names are hashed. So the
Uri
was something like:It works with any PDF viewer app I've tested except Adobe Reader. Today I did one last try to add a
.pdf
extension to the Content Uri (which is definitely not required) and when Adobe calls anopenFile()
function I strip the extension away. VOILA, it works!!!Update
Please make sure that also
_display_name
column yourContentProvider
returns as result ofquery(Uri, String[], String, String[], String)
query also contains.pdf
extension!!!Note
Tested with Adobe Acrobat Reader version 16.3