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


Java DownloadManager.Query方法代碼示例

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


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

示例1: cancelAllDownloads

import android.app.DownloadManager; //導入方法依賴的package包/類
public static void cancelAllDownloads(Context context){
    if (receiver != null) {
        context.unregisterReceiver(receiver);
        receiver = null;
    }

    DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterByStatus(
            DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PAUSED|
            DownloadManager.STATUS_PENDING|DownloadManager.STATUS_RUNNING);
    Cursor cur = manager.query(query);
    while (cur.moveToNext()){
        manager.remove(cur.getLong(cur.getColumnIndex(DownloadManager.COLUMN_ID)));
    }
    cur.close();
}
 
開發者ID:PaulKlinger,項目名稱:Sprog-App,代碼行數:18,代碼來源:PoemsLoader.java

示例2: checkDownloadStatus

import android.app.DownloadManager; //導入方法依賴的package包/類
public WritableMap checkDownloadStatus(long downloadId) {

        DownloadManager.Query downloadQuery = new DownloadManager.Query();
        downloadQuery.setFilterById(downloadId);
        Cursor cursor = downloadManager.query(downloadQuery);
        HashMap<String, String> result = new HashMap<>();
        if (cursor.moveToFirst()) {
            result = getDownloadStatus(cursor, downloadId);
        } else {
            result.put("status", "UNKNOWN");
            result.put("reason", "COULD_NOT_FIND");
            result.put("downloadId", String.valueOf(downloadId));
        }
        WritableMap wmap = new WritableNativeMap();
        for (HashMap.Entry<String, String> entry : result.entrySet()) {
            wmap.putString(entry.getKey(), entry.getValue());
        }
        return wmap;
    }
 
開發者ID:master-atul,項目名稱:react-native-simple-download-manager,代碼行數:20,代碼來源:Downloader.java

示例3: checkDownloadStatus

import android.app.DownloadManager; //導入方法依賴的package包/類
private void checkDownloadStatus() {
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(mTaskId);
    Cursor c = mDownloadManager.query(query);
    if (c.moveToFirst()) {
        int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
        switch (status) {
           /* case DownloadManager.STATUS_PAUSED:
                break;
            case DownloadManager.STATUS_FAILED:
                break;
            case DownloadManager.STATUS_PENDING:
                break;
            case DownloadManager.STATUS_RUNNING:
                break;*/
            case DownloadManager.STATUS_SUCCESSFUL:

               AppUtil.installApk(this, filePath);
                break;
        }
    }


}
 
開發者ID:jeasinlee,項目名稱:AndroidBasicLibs,代碼行數:25,代碼來源:DownloadService.java

示例4: onReceive

import android.app.DownloadManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    final long downloadedId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);

    final DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(downloadedId);

    final Cursor cursor = mDownloadManager.query(query);

    if (cursor.moveToFirst() &&
            DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(
                    cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
        mIds.remove(downloadedId);

        if (mIds.isEmpty()) {
            Global.getInstance().getBus()
                    .post(new MSNEvent<>(MSNEvent.DOWNLOAD_COMPLETE, true));
        }
    } else {
        for (Long id : mIds) {
            mDownloadManager.remove(id);
        }

        Global.getInstance().getBus()
                .post(new MSNEvent<>(MSNEvent.DOWNLOAD_COMPLETE, false));
    }
}
 
開發者ID:huazhouwang,項目名稱:Synapse,代碼行數:28,代碼來源:MainService.java

示例5: getStatusById

import android.app.DownloadManager; //導入方法依賴的package包/類
private int getStatusById(DownloadManager downloadManager, long downloadId, String columnName) {
    DownloadManager.Query query = new DownloadManager.Query().setFilterById(downloadId);
    int result = -1;
    Cursor c = null;
    try {
        c = downloadManager.query(query);
        if (c != null && c.moveToFirst()) {
            result = c.getInt(c.getColumnIndex(columnName));
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return result;
}
 
開發者ID:shenhuanet,項目名稱:AndroidOpen,代碼行數:17,代碼來源:FirUpdater.java

示例6: getLocalUriForDownloadId

import android.app.DownloadManager; //導入方法依賴的package包/類
private @Nullable Uri getLocalUriForDownloadId(Context context, long downloadId) {
  DownloadManager       downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
  DownloadManager.Query query           = new DownloadManager.Query();
  query.setFilterById(downloadId);

  Cursor cursor = downloadManager.query(query);

  try {
    if (cursor != null && cursor.moveToFirst()) {
      String localUri  = cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI));

      if (localUri != null) {
        File   localFile = new File(Uri.parse(localUri).getPath());
        return Uri.fromFile(localFile);
      }
    }
  } finally {
    if (cursor != null) cursor.close();
  }

  return null;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:23,代碼來源:UpdateApkReadyListener.java

示例7: checkDownloadStatus

import android.app.DownloadManager; //導入方法依賴的package包/類
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,代碼行數:30,代碼來源:DownloadFileManager.java

示例8: queryDownloadStatus

import android.app.DownloadManager; //導入方法依賴的package包/類
/**
 * 查詢下載狀態
 */
public static int queryDownloadStatus(Context mContext, long downloadId) {
    DownloadManager downloadManager = (DownloadManager) mContext.getSystemService(DOWNLOAD_SERVICE);
    DownloadManager.Query downloadQuery = new DownloadManager.Query();
    downloadQuery.setFilterById(downloadId);
    Cursor cursor = downloadManager.query(downloadQuery);
    int status = 0;
    if (cursor.moveToFirst()) {
        status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
    }
    return status;
}
 
開發者ID:jianesrq0724,項目名稱:UpdateLibrary,代碼行數:15,代碼來源:DownloadUtils.java

示例9: onReceive

import android.app.DownloadManager; //導入方法依賴的package包/類
@Override
public void onReceive(final Context context, Intent intent)
{
	String action = intent.getAction();
	if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equalsIgnoreCase(action))
	{
		DownloadFactory utils = DownloadFactory.getInstance(context.getApplicationContext());
		long downId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
		
		if (utils.containsTask(downId))
		{
			Log.D("info", "Current down id is in download task list!!!");
			utils.remove(downId); // 從隊列中移除
			
			DownloadManager.Query query = new DownloadManager.Query().setFilterById(downId);
			
			Cursor cursor = utils.getDownloadManager().query(query);
			if (cursor != null && cursor.moveToFirst())
			{
				// 隻有一條記錄
				final long id = cursor.getLong(cursor.getColumnIndex("_id"));
				final String local_filename = cursor.getString(cursor.getColumnIndex("local_filename"));
				final String mediaprovider_uri = cursor.getString(cursor.getColumnIndex("mediaprovider_uri"));
				final String destination = cursor.getString(cursor.getColumnIndex("destination"));
				final String title = cursor.getString(cursor.getColumnIndex("title"));
				final String description = cursor.getString(cursor.getColumnIndex("description"));
				final String uri = cursor.getString(cursor.getColumnIndex("uri"));
				final String status = cursor.getString(cursor.getColumnIndex("status"));
				final String hint = cursor.getString(cursor.getColumnIndex("hint"));
				final String media_type = cursor.getString(cursor.getColumnIndex("media_type"));
				final String total_size = cursor.getString(cursor.getColumnIndex("total_size"));
				final String last_modified_timestamp = cursor.getString(cursor.getColumnIndex("last_modified_timestamp"));
				final String bytes_so_far = cursor.getString(cursor.getColumnIndex("bytes_so_far"));
				final String local_uri = cursor.getString(cursor.getColumnIndex("local_uri"));
				final String reason = cursor.getString(cursor.getColumnIndex("reason"));
				
				// 關閉
				cursor.close();
				
				if ("application/vnd.android.package-archive".equalsIgnoreCase(media_type))
				{
					// 下載完成後直接打開安裝界麵
					final File file = new File(local_filename);
					final String message = context.getString(R.string.download_install, title + "");
					Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
					
					new Thread(new Runnable()
					{
						
						@Override
						public void run()
						{
							Log.I(TAG, "Ready to install [" + title + "]");
							SystemClock.sleep(200);
							DownloadFactory.installApk(context, file);
						}
					}).start();
				}
			}
		}
	}
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:63,代碼來源:DownloadBroadcastReceiver.java

示例10: onReceive

import android.app.DownloadManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        DownloadManager.Query query = new DownloadManager.Query();
        query.setFilterById(mEnqueue);
        Cursor cursor = mDownloadManager.query(query);
        if (cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
            if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(columnIndex)) {
                installApk();
            }
        }
        stopSelf();
    }
}
 
開發者ID:betroy,項目名稱:xifan,代碼行數:16,代碼來源:DownLoadApkService.java

示例11: checkStatus

import android.app.DownloadManager; //導入方法依賴的package包/類
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,代碼行數:35,代碼來源:Downloader.java

示例12: getHentetStatus

import android.app.DownloadManager; //導入方法依賴的package包/類
public HentetStatus getHentetStatus(Udsendelse udsendelse) {
  if (!virker()) return null;
  tjekDataOprettet();

  HentetStatus hs = data.hentetStatusFraSlug.get(udsendelse.slug);
  if (hs != null && (hs.status==DownloadManager.STATUS_SUCCESSFUL || hs.status == DownloadManager.STATUS_FAILED)) {
    hs.statustekst = lavStatustekst(hs);
    return hs;
  }

  Long downloadId = data.downloadIdFraSlug.get(udsendelse.slug);
  if (downloadId == null) return null;
  DownloadManager.Query query = new DownloadManager.Query();
  query.setFilterById(downloadId);
  Cursor c = downloadService.query(query);
  if (c==null) return null; // fix for https://mint.splunk.com/dashboard/project/cd78aa05/errors/4066198043
  if (!c.moveToFirst()) {
    c.close();
    return null;
  }

  if (hs == null) {
    hs = new HentetStatus();
    data.hentetStatusFraSlug.put(udsendelse.slug, hs);
  }
  hs.status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
  hs.iAlt = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)) / 1000000;
  hs.hentet = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) / 1000000;
  hs.startUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
  hs.statustekst = lavStatustekst(hs);
  if (hs.status==DownloadManager.STATUS_FAILED || hs.status==DownloadManager.STATUS_PAUSED) {
    int grund = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
    Log.d(udsendelse.slug+ " hs.grund til fejl "+ grund);
    if (grund==DownloadManager.ERROR_INSUFFICIENT_SPACE) hs.statustekst += " - Ikke nok plads";
  }
  c.close();
  //if (!App.PRODUKTION) hs.statustekst+="\n"+hs.startUri+"\n"+hs.destinationFil; // til fejlfinding
  return hs;
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:40,代碼來源:HentedeUdsendelser.java

示例13: getDownloadStatus

import android.app.DownloadManager; //導入方法依賴的package包/類
private DownloadStatus getDownloadStatus(String uri, byte[] theirDigest) {
  DownloadManager       downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
  DownloadManager.Query query           = new DownloadManager.Query();

  query.setFilterByStatus(DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_SUCCESSFUL);

  long   pendingDownloadId = TextSecurePreferences.getUpdateApkDownloadId(context);
  byte[] pendingDigest     = getPendingDigest(context);
  Cursor cursor            = downloadManager.query(query);

  try {
    DownloadStatus status = new DownloadStatus(DownloadStatus.Status.MISSING, -1);

    while (cursor != null && cursor.moveToNext()) {
      int    jobStatus         = cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
      String jobRemoteUri      = cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_URI));
      long   downloadId        = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID));
      byte[] digest            = getDigestForDownloadId(downloadId);

      if (jobRemoteUri != null && jobRemoteUri.equals(uri) && downloadId == pendingDownloadId) {

        if (jobStatus == DownloadManager.STATUS_SUCCESSFUL    &&
            digest != null && pendingDigest != null           &&
            MessageDigest.isEqual(pendingDigest, theirDigest) &&
            MessageDigest.isEqual(digest, theirDigest))
        {
          return new DownloadStatus(DownloadStatus.Status.COMPLETE, downloadId);
        } else if (jobStatus != DownloadManager.STATUS_SUCCESSFUL) {
          status = new DownloadStatus(DownloadStatus.Status.PENDING, downloadId);
        }
      }
    }

    return status;
  } finally {
    if (cursor != null) cursor.close();
  }
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:39,代碼來源:UpdateApkJob.java

示例14: onReceive

import android.app.DownloadManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    mDatabase = new DBHelper(context);
    if ("android.intent.action.DOWNLOAD_COMPLETE".equals(action)) {
        Bundle extras = intent.getExtras();
        dmo=(DownloadManager)context.getSystemService(context.DOWNLOAD_SERVICE);
        DownloadManager.Query q = new DownloadManager.Query();
        q.setFilterById(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID));
        Cursor c = dmo.query(q);
        ArrayList<String> xcoords = (new HomeFragment()).getList();
        if (c.moveToFirst()) {
            int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
            if (status == DownloadManager.STATUS_SUCCESSFUL) {
                xcoords.remove(c.getString(c.getColumnIndex(DownloadManager.COLUMN_URI)));
                pref = new PrefManager(context);
                Toast.makeText(context,"Download Completed",Toast.LENGTH_LONG).show();
                String title = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
                String path= c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
                long size=(c.getLong(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES )));
                Bitmap curThumb = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.MICRO_KIND);
                mDatabase.addRecording(title, path,size,curThumb);
                mDatabase.close();
            }
            else
            {
                xcoords.remove(c.getString(c.getColumnIndex(DownloadManager.COLUMN_URI)));
            }
        }
        c.close();
    }
    else if ("android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED".equals(action))
    {
   //     Log.d(tag,"Notification clicked");
    }
    else
    {
     //   Log.d(tag,action);
    }
}
 
開發者ID:adarshgumashta,項目名稱:Facebook-Video-Downloader,代碼行數:41,代碼來源:DownloadReceiver.java

示例15: queryDownloadStatus

import android.app.DownloadManager; //導入方法依賴的package包/類
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,代碼行數:48,代碼來源:DownloadController.java


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