Я реализовал пользовательский поставщик контента, обслуживающий PDF-документы как ParcelFileDescriptor. Файлы хранятся в локальном хранилище с пометкой PRIVATE. На основе URI документы затем передаются выбранному приложению PDF.
Это работает для всех приложений просмотра PDF, кроме Adobe Reader. Может ли кто-нибудь подтвердить, что 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);
}
}
Все другие приложения для просмотра PDF вызывают этот метод, кроме 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 всегда пишет: «Неверный путь к файлу».
Заранее спасибо!!! Кей.