正在下载pdf文件?

时间:2018-11-03 05:25:49

标签: android android-studio savefiledialog

嘿,在将PDF下载到我的设备时遇到问题。因此,每当我单击下载或在创建的按钮上时,它都会下载,但无法打开。它显示为常规文件(3066.file,4322.file ... etc)而不是data.pdf。当它是文件时,除非将其重命名为.pdf,否则无法打开它;还会下载到错误的位置,请提供帮助。谢谢

long queueId;
DownloadManager downloadManager;
private Button downloadFileButton;

,所以我在单击按钮时调用此函数。

public void downloadFile() {
    //Here put-in youre download stuff
    //so download the file from your server
    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 req_query = new DownloadManager.Query();
                req_query.setFilterById(queueId);

                Cursor c = downloadManager.query(req_query);

                if(c.moveToFirst())
                {
                    int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if(DownloadManager.STATUS_SUCCESSFUL==c.getInt(columnIndex));
                }
            }
        }
    };
    registerReceiver(receiver,new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    downloadManager= (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse("https://drive.google.com/uc?authuser=0&id=1GbMV1S7QlSJEJdGgbP1cVb-bhrJmqaYa&export=download.pdf"));//<--Link
    queueId= downloadManager.enqueue(request);
}

0 个答案:

没有答案