use of android.app.DownloadManager in project Signal-Android by WhisperSystems.
the class UpdateApkReadyListener method isMatchingDigest.
private boolean isMatchingDigest(Context context, long downloadId, String theirEncodedDigest) {
try {
if (theirEncodedDigest == null)
return false;
byte[] theirDigest = Hex.fromStringCondensed(theirEncodedDigest);
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
FileInputStream fin = new FileInputStream(downloadManager.openDownloadedFile(downloadId).getFileDescriptor());
byte[] ourDigest = FileUtils.getFileDigest(fin);
fin.close();
return MessageDigest.isEqual(ourDigest, theirDigest);
} catch (IOException e) {
Log.w(TAG, e);
return false;
}
}
use of android.app.DownloadManager in project Klyph by jonathangerbaud.
the class KlyphDownloadManager method downloadFile.
private static void downloadFile(Context context, String url, String title, String desc, boolean notifOnProgress, boolean notifOnComplete, String systemDir, String appDir) {
File direct = new File(Environment.getExternalStorageDirectory() + systemDir + "/" + appDir);
if (!direct.exists()) {
boolean success = direct.mkdirs();
if (!success) {
direct = new File(Environment.getExternalStoragePublicDirectory(systemDir) + "/" + appDir);
if (!direct.exists()) {
success = direct.mkdirs();
}
}
}
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
if (!Android.isMinAPI(14)) {
url = url.replace("https://", "http://");
}
Uri Download_Uri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
if (Android.isMinAPI(11)) {
request.allowScanningByMediaScanner();
int visibility = 0;
if (notifOnComplete == true) {
visibility = DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED;
} else if (notifOnProgress == true) {
visibility = DownloadManager.Request.VISIBILITY_VISIBLE;
}
request.setNotificationVisibility(visibility);
}
request.setTitle(title);
request.setDescription(desc);
request.setDestinationInExternalPublicDir(systemDir, "/" + appDir + "/" + url.substring(url.lastIndexOf("/") + 1));
downloadManager.enqueue(request);
}
use of android.app.DownloadManager in project XposedInstaller by rovo89.
the class DownloadsUtil method getAllForUrl.
public static List<DownloadInfo> getAllForUrl(Context context, String url) {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(new Query());
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);
List<DownloadInfo> downloads = new ArrayList<>();
while (c.moveToNext()) {
if (!url.equals(c.getString(columnUri)))
continue;
int status = c.getInt(columnStatus);
String localFilename = c.getString(columnFilename);
if (status == DownloadManager.STATUS_SUCCESSFUL && !new File(localFilename).isFile()) {
dm.remove(c.getLong(columnId));
continue;
}
downloads.add(new DownloadInfo(c.getLong(columnId), c.getString(columnUri), c.getString(columnTitle), c.getLong(columnLastMod), localFilename, status, c.getInt(columnTotalSize), c.getInt(columnBytesDownloaded), c.getInt(columnReason)));
}
c.close();
Collections.sort(downloads);
return downloads;
}
use of android.app.DownloadManager in project XposedInstaller by rovo89.
the class DownloadsUtil method removeAllForLocalFile.
public static void removeAllForLocalFile(Context context, File file) {
file.delete();
String filename;
try {
filename = file.getCanonicalPath();
} catch (IOException e) {
Log.w(XposedApp.TAG, "Could not resolve path for " + file.getAbsolutePath(), e);
return;
}
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(new Query());
int columnId = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
int columnFilename = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_FILENAME);
List<Long> idsList = new ArrayList<>(1);
while (c.moveToNext()) {
String itemFilename = c.getString(columnFilename);
if (itemFilename != null) {
if (filename.equals(itemFilename)) {
idsList.add(c.getLong(columnId));
} else {
try {
if (filename.equals(new File(itemFilename).getCanonicalPath())) {
idsList.add(c.getLong(columnId));
}
} catch (IOException ignored) {
}
}
}
}
c.close();
if (idsList.isEmpty())
return;
long[] ids = new long[idsList.size()];
for (int i = 0; i < ids.length; i++) ids[i] = idsList.get(i);
dm.remove(ids);
}
use of android.app.DownloadManager in project XposedInstaller by rovo89.
the class DownloadsUtil method removeAllForUrl.
public static void removeAllForUrl(Context context, String url) {
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(new Query());
int columnId = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
int columnUri = c.getColumnIndexOrThrow(DownloadManager.COLUMN_URI);
List<Long> idsList = new ArrayList<>(1);
while (c.moveToNext()) {
if (url.equals(c.getString(columnUri)))
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(i);
dm.remove(ids);
}
Aggregations