PDF ドキュメントを ParcelFileDescriptor として提供するカスタム コンテンツ プロバイダを実装しました。ファイルは、プライベートとしてマークされたローカル ストレージに保存されます。URI に基づいて、ドキュメントは選択された pdf アプリケーションに渡されます。
これは、Adobe Reader を除くすべての PDF Viewer アプリケーションで機能します。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 は常に「無効なファイル パス」と表示します。
前もって感謝します!!!ケイ。