本文整理匯總了Java中android.app.DownloadManager.STATUS_SUCCESSFUL屬性的典型用法代碼示例。如果您正苦於以下問題:Java DownloadManager.STATUS_SUCCESSFUL屬性的具體用法?Java DownloadManager.STATUS_SUCCESSFUL怎麽用?Java DownloadManager.STATUS_SUCCESSFUL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.app.DownloadManager
的用法示例。
在下文中一共展示了DownloadManager.STATUS_SUCCESSFUL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkDownloadStatus
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;
}
}
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: onReceive
@Override
public void onReceive(Context context, Intent intent) {
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
if (id != -1) {
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor cursor = downloadManager.query(new DownloadManager.Query().setFilterById(id));
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) != DownloadManager.STATUS_SUCCESSFUL) {
String title = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TITLE));
Toast.makeText(context, context.getString(R.string.toast_download_failed, title), Toast.LENGTH_SHORT).show();
return;
}
}
ids.remove(id);
if (ids.isEmpty()) {
getAdapter().notifyItemChanged(getAdapterPosition(), new Object());
context.unregisterReceiver(this);
mBroadcastReceiver = null;
}
}
}
示例5: 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;
}
示例6: tjekOmHentet
public void tjekOmHentet(Udsendelse udsendelse) {
if (!virker()) return;
if (udsendelse.hentetStream == null) {
HentetStatus hs = getHentetStatus(udsendelse);
if (hs == null) return;
if (hs.status != DownloadManager.STATUS_SUCCESSFUL) return;
File file = new File(hs.destinationFil);
if (file.exists()) {
udsendelse.hentetStream = new Lydstream();
udsendelse.hentetStream.url = hs.destinationFil;
udsendelse.hentetStream.score = 500; // Rigtig god!
udsendelse.kanHøres = true;
Log.registrérTestet("Afspille hentet udsendelse", udsendelse.slug);
} else {
Log.rapporterFejl(new IllegalStateException("Fil " + file + " hentet, men fandtes ikke alligevel??!"));
}
}
/*
if (udsendelse.hentetStream!=null && !new File(udsendelse.hentetStream.url).canRead()) {
Log.d("Fil findes pt ikke" + udsendelse.hentetStream.url);
udsendelse.hentetStream = null;
}
*/
}
示例7: 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__);
}
示例8: 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;
}
}
}
示例9: doInBackground
@Override
public Pair<Integer, Boolean> doInBackground(Void...voids) {
DownloadManager manager =
(DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = manager.query(new DownloadManager.Query().setFilterById(
mDownloadItem.getSystemDownloadId()));
int statusIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
int reasonIndex = c.getColumnIndex(DownloadManager.COLUMN_REASON);
int titleIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
int status = DownloadManager.STATUS_FAILED;
Boolean canResolve = false;
if (c.moveToNext()) {
status = c.getInt(statusIndex);
String title = c.getString(titleIndex);
if (mDownloadInfo == null) {
// Chrome has been killed, reconstruct a DownloadInfo.
mDownloadInfo = new DownloadInfo.Builder()
.setFileName(title)
.setDescription(c.getString(
c.getColumnIndex(DownloadManager.COLUMN_DESCRIPTION)))
.setMimeType(c.getString(
c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE)))
.setContentLength(Long.parseLong(c.getString(
c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))))
.build();
}
if (status == DownloadManager.STATUS_SUCCESSFUL) {
mDownloadInfo = DownloadInfo.Builder.fromDownloadInfo(mDownloadInfo)
.setFileName(title)
.build();
mDownloadItem.setDownloadInfo(mDownloadInfo);
canResolve = canResolveDownloadItem(mContext, mDownloadItem, false);
} else if (status == DownloadManager.STATUS_FAILED) {
mFailureReason = c.getInt(reasonIndex);
manager.remove(mDownloadItem.getSystemDownloadId());
}
}
c.close();
return Pair.create(status, canResolve);
}
示例10: getDownloadStatus
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();
}
}
示例11: 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);
}
示例12: getHentetStatus
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;
}
示例13: downloadWithSystemManager
@ProtoMethod(description = "Downloads a file from a given Uri. Returns the progress", example = "")
public void downloadWithSystemManager(String url, final ReturnInterface callback) {
final DownloadManager dm = (DownloadManager) getContext().getSystemService(getContext().DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
final long enqueue = dm.enqueue(request);
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(enqueue);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int columnIndex = c
.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
if (callback != null) callback.event(null);
// callback successful
}
}
}
}
};
getContext().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
示例14: 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();
}
}
示例15: 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;
}
}
}