Search in sources :

Example 26 with DownloadManager

use of android.app.DownloadManager in project android_frameworks_base by crdroidandroid.

the class FilesActivityUiTest method testDownload_RetryUnsuccessful.

@Suppress
public void testDownload_RetryUnsuccessful() throws Exception {
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    // This downloads fails! But it'll still show up.
    dm.enqueue(new Request(Uri.parse("http://www.google.com/hamfancy")));
    bots.roots.openRoot("Downloads");
    UiObject doc = bots.directory.findDocument("Unsuccessful");
    doc.waitForExists(TIMEOUT);
    int toolType = Configurator.getInstance().getToolType();
    Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER);
    doc.click();
    Configurator.getInstance().setToolType(toolType);
    assertTrue(bots.main.findDownloadRetryDialog().exists());
    // to clear the dialog.
    device.pressBack();
}
Also used : UiObject(android.support.test.uiautomator.UiObject) Request(android.app.DownloadManager.Request) DownloadManager(android.app.DownloadManager) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 27 with DownloadManager

use of android.app.DownloadManager in project WeChatLuckyMoney by geeeeeeeeek.

the class DownloadUtil method enqueue.

public void enqueue(String url, Context context) {
    DownloadManager.Request r = new DownloadManager.Request(Uri.parse(url));
    r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Uber.apk");
    r.allowScanningByMediaScanner();
    r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    DownloadManager dm = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
    dm.enqueue(r);
}
Also used : DownloadManager(android.app.DownloadManager)

Example 28 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 29 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 30 with DownloadManager

use of android.app.DownloadManager in project Xposed-Tinted-Status-Bar by MohammadAG.

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<Long>();
    while (c.moveToNext()) {
        if (c.getLong(columnLastMod) < cutoff)
            idsList.add(c.getLong(columnId));
    }
    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)

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