DownloadManager.ACTION_DOWNLOAD_COMPLETE broadcast receiver receiving same download id more than once with different download statuses in Android

前端 未结 2 1003
青春惊慌失措
青春惊慌失措 2020-12-02 11:33

I am using Android DownloadManger System Service for downloading some files in following way

dwnId = mgr.enqueue(new DownloadManager.Request(serveruri)
             


        
2条回答
  •  臣服心动
    2020-12-02 12:13

    This is a reported bug see: http://code.google.com/p/android/issues/detail?id=18462

    The way around I found is to verify if the download was a success, if not ditch the intent or re-queue the file if it was never downloaded...

    Lost a couple of hours figuring that one :(

    ** Edit: adding code example **

    /**
     * Check if download was valid, see issue
     * http://code.google.com/p/android/issues/detail?id=18462
     * @param long1
     * @return
     */
    private boolean validDownload(long downloadId) {
    
        Log.d(TAG,"Checking download status for id: " + downloadId);
    
        //Verify if download is a success
        Cursor c= dMgr.query(new DownloadManager.Query().setFilterById(downloadId));
    
        if(c.moveToFirst()){            
            int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
    
            if(status == DownloadManager.STATUS_SUCCESSFUL){
                return true; //Download is valid, celebrate
            }else{
                int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
                Log.d(TAG, "Download not correct, status [" + status + "] reason [" + reason + "]");            
                return false;
            }   
        }               
        return false;                                   
    }
    

    For complete code see : https://github.com/flegare/JAV387_LaboWidget/blob/master/src/com/mobidroid/widgetfact/service/FactService.java

提交回复
热议问题