Search in sources :

Example 31 with DownloadManager

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;
}
Also used : DownloadManager(android.app.DownloadManager)

Example 32 with DownloadManager

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);
}
Also used : Query(android.app.DownloadManager.Query) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) DownloadManager(android.app.DownloadManager)

Example 33 with DownloadManager

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);
}
Also used : DownloadManager(android.app.DownloadManager)

Example 34 with DownloadManager

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));
}
Also used : Request(okhttp3.Request) DownloadManager(android.app.DownloadManager)

Example 35 with DownloadManager

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();
    }
}
Also used : Cursor(android.database.Cursor) DownloadManager(android.app.DownloadManager)

Aggregations

DownloadManager (android.app.DownloadManager)59 Cursor (android.database.Cursor)14 File (java.io.File)14 Uri (android.net.Uri)13 Request (android.app.DownloadManager.Request)12 Suppress (android.test.suitebuilder.annotation.Suppress)10 Query (android.app.DownloadManager.Query)9 Intent (android.content.Intent)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 UiObject (android.support.test.uiautomator.UiObject)5 Context (android.content.Context)3 View (android.view.View)3 Nullable (android.support.annotation.Nullable)2 AlertDialog (android.support.v7.app.AlertDialog)2 Response (com.android.volley.Response)2 VolleyError (com.android.volley.VolleyError)2 FileInputStream (java.io.FileInputStream)2 JSONObject (org.json.JSONObject)2 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)1