use of android.app.DownloadManager in project Signal-Android by WhisperSystems.
the class UpdateApkReadyListener method getLocalUriForDownloadId.
@Nullable
private 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;
}
use of android.app.DownloadManager in project Xposed-Tinted-Status-Bar by MohammadAG.
the class DownloadsUtil method getById.
public static DownloadInfo getById(Context context, long id) {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(new Query().setFilterById(id));
if (!c.moveToFirst())
return null;
int columnId = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
int columnUri = c.getColumnIndexOrThrow(DownloadManager.COLUMN_URI);
int columnTitle = c.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE);
int columnLastMod = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP);
int columnFilename = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_FILENAME);
int columnStatus = c.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS);
int columnTotalSize = c.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
int columnBytesDownloaded = c.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
int columnReason = c.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON);
String localFilename = c.getString(columnFilename);
if (localFilename != null && !localFilename.isEmpty() && !new File(localFilename).isFile()) {
dm.remove(c.getLong(columnId));
return null;
}
return new DownloadInfo(c.getLong(columnId), c.getString(columnUri), c.getString(columnTitle), c.getLong(columnLastMod), localFilename, c.getInt(columnStatus), c.getInt(columnTotalSize), c.getInt(columnBytesDownloaded), c.getInt(columnReason));
}
use of android.app.DownloadManager in project Xposed-Tinted-Status-Bar by MohammadAG.
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 xabber-android by redsolution.
the class FileManager method saveFileToDownloads.
public static void saveFileToDownloads(File srcFile) throws IOException {
LogManager.i(FileManager.class, "Saving file to downloads");
final File dstFile = copyFile(srcFile, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + srcFile.getName());
String mimeTypeFromExtension = getFileMimeType(dstFile);
if (mimeTypeFromExtension == null) {
mimeTypeFromExtension = "application/octet-stream";
}
final DownloadManager downloadManager = (DownloadManager) Application.getInstance().getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.addCompletedDownload(dstFile.getName(), String.format(Application.getInstance().getString(R.string.received_by), Application.getInstance().getString(R.string.application_title_short)), true, mimeTypeFromExtension, dstFile.getPath(), dstFile.length(), true);
}
use of android.app.DownloadManager in project AndroidChromium by JackyAndroid.
the class DownloadManagerDelegate method removeCompletedDownload.
/**
* Removes a download from Android DownloadManager.
* @param downloadGuid The GUID of the download.
*/
void removeCompletedDownload(String downloadGuid) {
long downloadId = removeDownloadIdMapping(downloadGuid);
if (downloadId != INVALID_SYSTEM_DOWNLOAD_ID) {
DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
manager.remove(downloadId);
}
}
Aggregations