Android DownloadManager get filename

前端 未结 5 756
醉酒成梦
醉酒成梦 2020-12-08 10:37

In my app you can download some files. I used the Android DownloadManager class for downloading. After the download is completed, it should show me a message th

5条回答
  •  情书的邮戳
    2020-12-08 10:54

    I think you want to put something like this inside your if block. Replace YOUR_DM with your DownloadManager instance.

    Bundle extras = intent.getExtras();
    DownloadManager.Query q = new DownloadManager.Query();
    q.setFilterById(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID));
    Cursor c = YOUR_DM.query(q);
    
    if (c.moveToFirst()) {
        int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
        if (status == DownloadManager.STATUS_SUCCESSFUL) {
            // process download
            title = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
            // get other required data by changing the constant passed to getColumnIndex
        }
    }
    

提交回复
热议问题