本文整理匯總了Java中android.app.DownloadManager.STATUS_PENDING屬性的典型用法代碼示例。如果您正苦於以下問題:Java DownloadManager.STATUS_PENDING屬性的具體用法?Java DownloadManager.STATUS_PENDING怎麽用?Java DownloadManager.STATUS_PENDING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.app.DownloadManager
的用法示例。
在下文中一共展示了DownloadManager.STATUS_PENDING屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: lavStatustekst
public static String lavStatustekst(HentetStatus hs) {
if (hs.status == DownloadManager.STATUS_SUCCESSFUL) {
if (hs.statusFlytningIGang) return App.res.getString(R.string.Flytter__);
if (new File(hs.destinationFil).canRead()) return App.res.getString(R.string.Klar___mb_, hs.iAlt);
return App.res.getString(R.string._ikke_tilgængelig_);
} else if (hs.status == DownloadManager.STATUS_FAILED) {
return App.res.getString(R.string.Mislykkedes);
} else if (hs.status == DownloadManager.STATUS_PENDING) {
return App.res.getString(R.string.Venter___);
} else if (hs.status == DownloadManager.STATUS_PAUSED) {
return App.res.getString(R.string.Hentning_pauset__) + App.res.getString(R.string.Hentet___mb_af___mb, hs.hentet, hs.iAlt);
}
// RUNNING
if (hs.hentet > 0 || hs.iAlt > 0) return App.res.getString(R.string.Hentet___mb_af___mb, hs.hentet, hs.iAlt);
return App.res.getString(R.string.Henter__);
}
示例3: 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;
}
}
}
示例4: 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);
}
示例5: 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();
}
}
示例6: 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;
}
}
}
示例7: 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);
}
示例8: 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);
}
}
}
示例9: 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);
}