Search in sources :

Example 36 with DownloadManager

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;
}
Also used : Cursor(android.database.Cursor) DownloadManager(android.app.DownloadManager) File(java.io.File) Nullable(android.support.annotation.Nullable)

Example 37 with DownloadManager

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

Example 38 with DownloadManager

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

Example 39 with DownloadManager

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

Example 40 with DownloadManager

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);
    }
}
Also used : 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