在Oreo上的DownloadManager pdf

时间:2018-10-10 14:20:11

标签: android android-download-manager androidpdfviewer

我在Android Oreo上下载和可视化PDF时遇到问题。 代码,下载pdf(在通知中显示加载程序)。下载完成后,广播会打开选择器,但是当我选择Adobe Reader或anothe时,它说:“它无法访问此文件。请检查路径或网络”。 我错了吗?

String url = "https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf"
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
enqueue = dm.enqueue(request);

BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
            DownloadManager.Query query = new DownloadManager.Query();
            query.setFilterById(enqueue);
            Cursor c = dm.query(query);
            if (c.moveToFirst()) {
                int columnIndex = c
                        .getColumnIndex(DownloadManager.COLUMN_STATUS);
                if (DownloadManager.STATUS_SUCCESSFUL == c
                        .getInt(columnIndex)) {
                    String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                    try {
                        Intent intent1 = new Intent();
                        //intent1.setPackage("com.adobe.reader");
                        intent1.setDataAndType(Uri.parse(uriString), "application/pdf");
                        Intent chooserIntent = Intent.createChooser(intent1, "Apri il pdf con:");
                        startActivity(chooserIntent);
                    } catch (ActivityNotFoundException activityNotFoundException) {
                    }
                }
            }
        }
    }
};

0 个答案:

没有答案