當前位置: 首頁>>代碼示例>>Java>>正文


Java DownloadManager.STATUS_RUNNING屬性代碼示例

本文整理匯總了Java中android.app.DownloadManager.STATUS_RUNNING屬性的典型用法代碼示例。如果您正苦於以下問題:Java DownloadManager.STATUS_RUNNING屬性的具體用法?Java DownloadManager.STATUS_RUNNING怎麽用?Java DownloadManager.STATUS_RUNNING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.app.DownloadManager的用法示例。


在下文中一共展示了DownloadManager.STATUS_RUNNING屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onClickUpdate

/**
 * 點擊下載
 */
public void onClickUpdate() {
    if (mDownloadId != 0) {//downloadID不為默認值,表示存在下載任務
        int status = DownloadUtils.queryDownloadStatus(mContext, mDownloadId);
        Log.e("TAG", status + "");
        switch (status) {
            case DownloadManager.STATUS_RUNNING://下載中
                DownloadToast.showShort(mContext, "正在下載,請稍後");
                break;
            case DownloadManager.STATUS_FAILED://下載失敗
                startDownApk();//重新開始下載
                break;
            case DownloadManager.STATUS_SUCCESSFUL://下載成功
                installApk();
                break;
            default:
                break;
        }
    } else {//無下載任務,開始下載
        startDownApk();
    }
}
 
開發者ID:jianesrq0724,項目名稱:UpdateLibrary,代碼行數:24,代碼來源:UpdateDialog.java

示例2: onClickUpdate

/**
 * 點擊下載
 */
public void onClickUpdate() {
    if (mDownloadId != 0) {//downloadID不為默認值,表示存在下載任務
        int status = DownloadUtils.queryDownloadStatus(this, mDownloadId);
        Log.e("TAG", status + "");
        switch (status) {
            case DownloadManager.STATUS_RUNNING://下載中
                DownloadToast.showShort(this, "正在下載,請稍後");
                break;
            case DownloadManager.STATUS_FAILED://下載失敗
                startDownApk();//重新開始下載
                break;
            case DownloadManager.STATUS_SUCCESSFUL://下載成功
                installApk();
                break;
            default:
                break;
        }
    } else {//無下載任務,開始下載
        startDownApk();
    }
}
 
開發者ID:jianesrq0724,項目名稱:UpdateLibrary,代碼行數:24,代碼來源:UpdateActivity.java

示例3: getStatusTextResId

@StringRes
public int getStatusTextResId() {
    int statusText = 0;
    switch (status) {
        case DownloadManager.STATUS_FAILED:
            statusText = (R.string.STATUS_FAILED);
            break;
        case DownloadManager.STATUS_PAUSED:
            statusText = (R.string.STATUS_PAUSED);

            break;
        case DownloadManager.STATUS_PENDING:
            statusText = (R.string.STATUS_PENDING);
            break;
        case DownloadManager.STATUS_RUNNING:
            statusText = (R.string.STATUS_RUNNING);
            break;
        case DownloadManager.STATUS_SUCCESSFUL:
            statusText = (R.string.STATUS_SUCCESSFUL);
            break;
    }
    return statusText;
}
 
開發者ID:fekracomputers,項目名稱:IslamicLibraryAndroid,代碼行數:23,代碼來源:DownloadInfo.java

示例4: checkDownloadStatus

private void checkDownloadStatus() {
    String url = rctParams.hasKey("url") ? rctParams.getString("url") : null;
    String description = rctParams.hasKey("description") ? rctParams.getString("description") : "downloading";
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(mTaskId);//篩選下載任務,傳入任務ID,可變參數
    Cursor c = downloadManager.query(query);
    if (c.moveToFirst()) {
        int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
        String downloadPath = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
        switch (status) {
            case DownloadManager.STATUS_PAUSED:
            case DownloadManager.STATUS_PENDING:
            case DownloadManager.STATUS_RUNNING:
                WritableMap map = Arguments.createMap();
                map.putInt("status", status);
                map.putString("description", description);
                map.putString("url", url);
                sendEvent(mApplicationContext,EVENT_NAME,map);
                break;
            case DownloadManager.STATUS_SUCCESSFUL:
                // String downloadPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + File.separator + description;
                sendMessage(status, downloadPath, url);
                break;
            case DownloadManager.STATUS_FAILED:
                sendMessage(status, description, url);
                break;
        }
    }
}
 
開發者ID:liuhong1happy,項目名稱:react-native-download-manager,代碼行數:29,代碼來源:DownloadFileManager.java

示例5: statusMessage

private String statusMessage(Cursor c) {
    String msg;

    switch (c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
        case DownloadManager.STATUS_FAILED:
            msg = "DownloadInfo failed";
            break;

        case DownloadManager.STATUS_PAUSED:
            msg = "DownloadInfo paused";
            break;

        case DownloadManager.STATUS_PENDING:
            msg = "DownloadInfo pending";
            break;

        case DownloadManager.STATUS_RUNNING:
            msg = "DownloadInfo in progress";
            break;

        case DownloadManager.STATUS_SUCCESSFUL:
            msg = "DownloadInfo complete";
            break;

        default:
            msg = "DownloadInfo is nowhere in sight";
            break;
    }

    return (msg);
}
 
開發者ID:fekracomputers,項目名稱:IslamicLibraryAndroid,代碼行數:31,代碼來源:SplashActivity.java

示例6: checkStatus

private void checkStatus() {
    //cause SQLiteException at 樂視 LE X820 Android 6.0.1,level 23
    try{
        DownloadManager.Query query = new DownloadManager.Query();
        query.setFilterById(downloadId);
        Cursor c = downloadManager.query(query);
        if (c.moveToFirst()) {
            int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
            switch (status) {
                case DownloadManager.STATUS_PAUSED:
                    break;
                case DownloadManager.STATUS_PENDING:
                    break;
                case DownloadManager.STATUS_RUNNING:
                    break;
                case DownloadManager.STATUS_SUCCESSFUL:
                    String tip = mContext.getString(R.string.download_complete)
                            .concat("\n").concat(getFilePath());
                    Toasty.success(mContext, tip).show();
                    unregister();
                    break;
                case DownloadManager.STATUS_FAILED:
                    Toasty.error(mContext, mContext.getString(R.string.download_failed)).show();
                    unregister();
                    break;
            }
        }
        c.close();
    }catch (SQLiteException e){
        Logger.d(e);
        unregister();
    }

}
 
開發者ID:ThirtyDegreesRay,項目名稱:OpenHub,代碼行數:34,代碼來源:Downloader.java

示例7: queryProgress

private void queryProgress(TimerTask task) {

        Cursor cursor = manager.query(query);
        if (cursor.moveToFirst()) {
            int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
            int reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
            Log.e("原因",String.valueOf(reason));
            switch (status) {
                case DownloadManager.STATUS_FAILED :
                    if (task != null)
                    task.cancel();
                    break;
                case DownloadManager.STATUS_PAUSED :
                    if (task != null)
                    task.cancel();
                    //發廣播通知activity下載暫停了
                    Intent intent = new Intent();
                    intent.setAction("download has been paused");
                    sendBroadcast(intent);
                    break;
                case DownloadManager.STATUS_RUNNING :
                    checkDownloadProgress(cursor);
                    break;
            }

        }
        cursor.close();
    }
 
開發者ID:BittleDragon,項目名稱:MyRepository,代碼行數:28,代碼來源:DownloadService.java

示例8: queryDownloadStatus

private void queryDownloadStatus() {
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(lastDownloadId);
    Cursor c = downloadManager.query(query);
    if(c != null && c.moveToFirst()) {
        int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));

        int reasonIdx = c.getColumnIndex(DownloadManager.COLUMN_REASON);
        int titleIdx = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
        int fileSizeIdx =
                c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
        int bytesDLIdx =
                c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
        String title = c.getString(titleIdx);
        int fileSize = c.getInt(fileSizeIdx);
        int bytesDL = c.getInt(bytesDLIdx);

        // Translate the pause reason to friendly text.
        int reason = c.getInt(reasonIdx);
        StringBuilder sb = new StringBuilder();
        sb.append(title).append("\n");
        sb.append("Downloaded ").append(bytesDL).append(" / " ).append(fileSize);

        // Display the status
        Log.d(TAG, sb.toString());
        switch(status) {
            case DownloadManager.STATUS_PAUSED:
                Log.v(TAG, "STATUS_PAUSED");
            case DownloadManager.STATUS_PENDING:
                Log.v(TAG, "STATUS_PENDING");
            case DownloadManager.STATUS_RUNNING:
                // 正在下載,不做任何事情
                Log.v(TAG, "STATUS_RUNNING");
                break;
            case DownloadManager.STATUS_SUCCESSFUL:
                // 完成
                Log.v(TAG, "下載完成");
                downloadManager.remove(lastDownloadId);
                break;
            case DownloadManager.STATUS_FAILED:
                // 清除已下載的內容,重新下載
                Log.v(TAG, "STATUS_FAILED");
                downloadManager.remove(lastDownloadId);
                break;
        }
    }
}
 
開發者ID:aliyun,項目名稱:aliyun-cloudphotos-android-demo,代碼行數:47,代碼來源:DownloadController.java

示例9: includeDownloadFromCursor

@SuppressLint("InlinedApi")
private void includeDownloadFromCursor(MatrixCursor result, Cursor cursor) {
       final long id = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID));
       final String docId = String.valueOf(id);

       final String displayName = cursor.getString(
               cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE));
       String summary = cursor.getString(
               cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_DESCRIPTION));
       String mimeType = cursor.getString(
               cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE));
       if (mimeType == null) {
           // Provide fake MIME type so it's openable
           mimeType = "vnd.android.document/file";
       }
       Long size = cursor.getLong(
               cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
       if (size == -1) {
           size = null;
       }

       final int status = cursor.getInt(
               cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
       switch (status) {
           case DownloadManager.STATUS_SUCCESSFUL:
               break;
           case DownloadManager.STATUS_PAUSED:
               summary = getContext().getString(R.string.download_queued);
               break;
           case DownloadManager.STATUS_PENDING:
               summary = getContext().getString(R.string.download_queued);
               break;
           case DownloadManager.STATUS_RUNNING:
               final long progress = cursor.getLong(cursor.getColumnIndexOrThrow(
                       DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
               if (size != null) {
                   final long percent = progress * 100 / size;
                   summary = getContext().getString(R.string.download_running_percent, percent);
               } else {
                   summary = getContext().getString(R.string.download_running);
               }
               break;
           case DownloadManager.STATUS_FAILED:
           default:
               summary = getContext().getString(R.string.download_error);
               break;
       }

       int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE;
       if (mimeType != null && mimeType.startsWith("image/")) {
           flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
       }

       final long lastModified = cursor.getLong(
               cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP));

       final RowBuilder row = result.newRow();
       row.add(Document.COLUMN_DOCUMENT_ID, docId);
       row.add(Document.COLUMN_DISPLAY_NAME, displayName);
       row.add(Document.COLUMN_SUMMARY, summary);
       row.add(Document.COLUMN_SIZE, size);
       row.add(Document.COLUMN_MIME_TYPE, mimeType);
       row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
       row.add(Document.COLUMN_FLAGS, flags);
   }
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:65,代碼來源:DownloadStorageProvider.java

示例10: queryDownloadStatus

private void queryDownloadStatus() {
        DownloadManager.Query query = new DownloadManager.Query();
        query.setFilterById(transform());
        Cursor c = mDownloadManager.query(query);
        if(c == null){
            return;
        }
        for(c.moveToFirst();!c.isAfterLast();c.moveToNext()){
            int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
            int reasonIdx = c.getColumnIndex(DownloadManager.COLUMN_REASON);
            int downloadIdx = c.getColumnIndex(DownloadManager.COLUMN_ID);
            int titleIdx = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
            int fileSizeIdx = c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
            int bytesDLIdx = c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
            int timestampx = c.getColumnIndex(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP);
            int urlx = c.getColumnIndex(DownloadManager.COLUMN_URI);
            int filePathx = c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);

            String title = c.getString(titleIdx);
            int fileSize = c.getInt(fileSizeIdx);
            int bytesDL = c.getInt(bytesDLIdx);
            int reason = c.getInt(reasonIdx);
            long donwloadId = c.getLong(downloadIdx);
            long timestamp = c.getLong(timestampx);
            String url = c.getString(urlx);
            String filePath = c.getString(filePathx);
//            StringBuilder sb = new StringBuilder();
//            sb.append(title).append("\n");
//            sb.append("Downloaded ").append(bytesDL).append(" / " ).append(fileSize);
//
//            // Display the status
//            Log.d("tag", sb.toString());

//            Log.i("xym","" + task);
            DownloadTask task = new DownloadTask(donwloadId , url , filePath , fileSize , bytesDL , -1);

            Log.i("xym","" + task);
            switch(status) {
                case DownloadManager.STATUS_PAUSED:
                    Log.v("tag", "STATUS_PAUSED");
                case DownloadManager.STATUS_PENDING:
                    Log.v("tag", "STATUS_PENDING");
                case DownloadManager.STATUS_RUNNING:
                    //正在下載,不做任何事情
                    Log.v("tag", "STATUS_RUNNING");
                    break;
                case DownloadManager.STATUS_SUCCESSFUL:
                    //完成
                    Log.v("tag", "下載完成");
                    task.setFinish(true);
//                  dowanloadmanager.remove(lastDownloadId);
                    break;
                case DownloadManager.STATUS_FAILED:
                    //清除已下載的內容,重新下載
                    Log.v("tag", "STATUS_FAILED");
                    task.setFinish(true);
                    mDownloadManager.remove(donwloadId);
                    break;
            }


            if(mDownloadChangedListener != null){
                mDownloadChangedListener.update(task);
            }

        }

    }
 
開發者ID:zhuangzaiku,項目名稱:AndroidCollection,代碼行數:68,代碼來源:SystemDownloader.java

示例11: downloadVideoFile

@ReactMethod public void downloadVideoFile(String uri, final Promise downloadPromise) {
  this.downloadUri = uri;
  this.downloadPromise = downloadPromise;
  dm = (DownloadManager) getReactApplicationContext().
      getSystemService(Context.DOWNLOAD_SERVICE);

  getReactApplicationContext().
      registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

  if (Prefs.isUriAlreadyDownloaded(uri)) {
    WritableMap localUri = new WritableNativeMap();
    localUri.putString("uri", Prefs.getLocalUri());
    downloadPromise.resolve(localUri);
  } else if(Prefs.getDownloadId() != -1) {
    // if file downloaded in background, save it to internal storage
    Cursor c = dm.query(new DownloadManager.Query().setFilterById(Prefs.getDownloadId()));
    if (c.moveToFirst()) {
      int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
      switch (status) {
        case DownloadManager.STATUS_PAUSED:
          break;
        case DownloadManager.STATUS_PENDING:
          break;
        case DownloadManager.STATUS_RUNNING:
          break;
        case DownloadManager.STATUS_SUCCESSFUL:
          Prefs.setDownloading(false);
          enqueue = Prefs.getDownloadId();
          saveToLocalStorage();
          break;
        case DownloadManager.STATUS_FAILED:
          break;
      }
    }

  } else {
    if (!Prefs.isDownloading()) {
      if (!Prefs.isUriAlreadyDownloaded(uri)) {
        Prefs.setDownloading(true);
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(uri));
        request.setVisibleInDownloadsUi(false);
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);

        request.setDestinationInExternalFilesDir(getReactApplicationContext(),
            DIRECTORY_DOWNLOADS, URLUtil.guessFileName(uri, null, null) + ".mp4");

        enqueue = dm.enqueue(request);
        Prefs.saveDownloadId(enqueue);
      }
    }
  }

  progressRunnable = new Runnable() {
    @Override
    public void run() {
      checkProgress();
    }
  };

  future = this.executor.scheduleWithFixedDelay(progressRunnable, 1L, 1, TimeUnit.SECONDS);


}
 
開發者ID:humaniq,項目名稱:react-native-android-library-humaniq-api,代碼行數:63,代碼來源:DownloadModule.java


注:本文中的android.app.DownloadManager.STATUS_RUNNING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。