我正在使用Android下載管理器類。在所有下載完成後,我需要編寫「下載完成」。我嘗試了一些東西,它的工作。但是在這裏它是在文件完成後寫入文件。我只需要寫一次(畢竟完成了)。我也嘗試沒有遊標。但我未能實現。如何從Android下載管理器完成所有下載後通知
public class DownloadReceiver extends BroadcastReceiver {
Context context;
@Override
public void onReceive(Context context, Intent intent) {
long receivedID = intent.getLongExtra(
DownloadManager.EXTRA_DOWNLOAD_ID, -1L);
DownloadManager mgr = (DownloadManager)
context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(receivedID);
Cursor cur = mgr.query(query);
int index = cur.getColumnIndex(DownloadManager.COLUMN_STATUS);
if(cur.) {
String filePath = cur.getString(cur.getColumnIndex(DownloadManager.COLUMN_TITLE));
if(cur.getInt(index) == DownloadManager.STATUS_SUCCESSFUL){
DatabaseHandler dh = new DatabaseHandler(context);
dh.addDownloadComplete(new DownloadComplete("Download Complete"));
}
}
cur.close();
}}
所有下載完成後,你的意思是什麼?你是否有一組下載ID要檢查它們是否完整,或者你只是想檢查DownloadManager中的每個下載(無論它是否來自你的應用)是否完成? –
我正在從列表中下載文件。在上面的例子中,它逐個檢查,然後寫下載逐個完成。但我需要的是,下載完所有文件後,我需要寫下載完成一次。 – venura