use of android.app.DownloadManager in project GeekNews by codeestX.
the class UpdateService method startDownload.
private void startDownload() {
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(MyApis.APK_DOWNLOAD_URL));
request.setTitle("GeekNews");
request.setDescription("新版本下载中");
request.setMimeType("application/vnd.android.package-archive");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "geeknews.apk");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
dm.enqueue(request);
ToastUtil.shortShow("后台下载中,请稍候...");
}
use of android.app.DownloadManager in project Xposed-Tinted-Status-Bar by MohammadAG.
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<DownloadInfo>();
while (c.moveToNext()) {
if (!url.equals(c.getString(columnUri)))
continue;
String localFilename = c.getString(columnFilename);
if (localFilename != null && !localFilename.isEmpty() && !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, c.getInt(columnStatus), c.getInt(columnTotalSize), c.getInt(columnBytesDownloaded), c.getInt(columnReason)));
}
Collections.sort(downloads);
return downloads;
}
use of android.app.DownloadManager in project Xposed-Tinted-Status-Bar by MohammadAG.
the class DownloadsUtil method add.
public static DownloadInfo add(Context context, String title, String url, DownloadFinishedCallback callback) {
removeAllForUrl(context, url);
synchronized (mCallbacks) {
mCallbacks.put(url, callback);
}
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse(url));
request.setTitle(title);
request.setMimeType(MIME_TYPE_APK);
request.setNotificationVisibility(Request.VISIBILITY_VISIBLE);
long id = dm.enqueue(request);
return getById(context, id);
}
use of android.app.DownloadManager in project Xposed-Tinted-Status-Bar by MohammadAG.
the class PluginDownloaderActivity method downloadPlugin.
private void downloadPlugin(Plugin plugin) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(plugin.url));
request.setDescription(getString(R.string.download_description));
request.setTitle(plugin.packageLabel);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setVisibleInDownloadsUi(false);
String fileName = plugin.url.substring(plugin.url.lastIndexOf("/"));
request.setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, fileName);
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
mDownloadIds.add(manager.enqueue(request));
}
use of android.app.DownloadManager in project Signal-Android by WhisperSystems.
the class UpdateApkJob method getDigestForDownloadId.
@Nullable
private byte[] getDigestForDownloadId(long downloadId) {
try {
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
FileInputStream fin = new FileInputStream(downloadManager.openDownloadedFile(downloadId).getFileDescriptor());
byte[] digest = FileUtils.getFileDigest(fin);
fin.close();
return digest;
} catch (IOException e) {
Log.w(TAG, e);
return null;
}
}
Aggregations