Search in sources :

Example 1 with DownloadManager

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("后台下载中,请稍候...");
}
Also used : DownloadManager(android.app.DownloadManager)

Example 2 with DownloadManager

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

Example 3 with DownloadManager

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

Example 4 with DownloadManager

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

Example 5 with DownloadManager

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

Aggregations

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