use of android.app.DownloadManager in project nmid-headline by miao1007.
the class DownloadUtils method DownloadApkWithProgress.
public static long DownloadApkWithProgress(Context context, String url) {
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDestinationInExternalPublicDir("/headline", "update.apk");
request.setTitle("Updating" + context.getPackageName());
request.setMimeType(MINETYPE_APPLCATION);
long downloadId = downloadManager.enqueue(request);
return downloadId;
}
use of android.app.DownloadManager in project XposedInstaller by rovo89.
the class DownloadsUtil method removeOutdated.
public static void removeOutdated(Context context, long cutoff) {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(new Query());
int columnId = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
int columnLastMod = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP);
List<Long> idsList = new ArrayList<>();
while (c.moveToNext()) {
if (c.getLong(columnLastMod) < cutoff)
idsList.add(c.getLong(columnId));
}
c.close();
if (idsList.isEmpty())
return;
long[] ids = new long[idsList.size()];
for (int i = 0; i < ids.length; i++) ids[i] = idsList.get(0);
dm.remove(ids);
}
use of android.app.DownloadManager in project XposedInstaller by rovo89.
the class DownloadsUtil method removeById.
public static void removeById(Context context, long id) {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
dm.remove(id);
}
use of android.app.DownloadManager in project Signal-Android by WhisperSystems.
the class UpdateApkJob method handleDownloadStart.
private void handleDownloadStart(String uri, String versionName, byte[] digest) {
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(uri));
downloadRequest.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
downloadRequest.setTitle("Downloading Signal update");
downloadRequest.setDescription("Downloading Signal " + versionName);
downloadRequest.setVisibleInDownloadsUi(false);
downloadRequest.setDestinationInExternalFilesDir(context, null, "signal-update.apk");
if (Build.VERSION.SDK_INT >= 11) {
downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
}
long downloadId = downloadManager.enqueue(downloadRequest);
TextSecurePreferences.setUpdateApkDownloadId(context, downloadId);
TextSecurePreferences.setUpdateApkDigest(context, Hex.toStringCondensed(digest));
}
use of android.app.DownloadManager in project Signal-Android by WhisperSystems.
the class UpdateApkJob method 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();
}
}
Aggregations