Search in sources :

Example 41 with DownloadManager

use of android.app.DownloadManager in project AndroidChromium by JackyAndroid.

the class DownloadManagerService method getLaunchIntentFromDownloadId.

/**
     * Return the intent to launch for a given download item.
     *
     * @param context    Context of the app.
     * @param filePath   Path to the file.
     * @param downloadId ID of the download item in DownloadManager.
     * @param isSupportedMimeType Whether the MIME type is supported by browser.
     * @return the intent to launch for the given download item.
     */
static Intent getLaunchIntentFromDownloadId(Context context, @Nullable String filePath, long downloadId, boolean isSupportedMimeType) {
    assert !ThreadUtils.runningOnUiThread();
    DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    Uri contentUri = manager.getUriForDownloadedFile(downloadId);
    if (contentUri == null)
        return null;
    String mimeType = manager.getMimeTypeForDownloadedFile(downloadId);
    if (isSupportedMimeType) {
        // Redirect the user to an internal media viewer.  The file path is necessary to show
        // the real file path to the user instead of a content:// download ID.
        Uri fileUri = contentUri;
        if (filePath != null)
            fileUri = Uri.fromFile(new File(filePath));
        return DownloadUtils.getMediaViewerIntentForDownloadItem(fileUri, contentUri, mimeType);
    }
    return DownloadUtils.createViewIntentForDownloadItem(contentUri, mimeType);
}
Also used : DownloadManager(android.app.DownloadManager) Uri(android.net.Uri) File(java.io.File)

Example 42 with DownloadManager

use of android.app.DownloadManager in project platform_frameworks_base by android.

the class FilesActivityUiTest method testDownload_Queued.

// We don't really need to test the entirety of download support
// since downloads is (almost) just another provider.
@Suppress
public void testDownload_Queued() throws Exception {
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    // This downloads ends up being queued (because DNS can't be resolved).
    // We'll still see an entry in the downloads UI with a "Queued" label.
    dm.enqueue(new Request(Uri.parse("http://hammychamp.toodles")));
    bots.roots.openRoot("Downloads");
    bots.directory.assertDocumentsPresent("Queued");
}
Also used : Request(android.app.DownloadManager.Request) DownloadManager(android.app.DownloadManager) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 43 with DownloadManager

use of android.app.DownloadManager in project platform_frameworks_base by android.

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 44 with DownloadManager

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

the class FilesActivityUiTest method testDownload_Queued.

// We don't really need to test the entirety of download support
// since downloads is (almost) just another provider.
@Suppress
public void testDownload_Queued() throws Exception {
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    // This downloads ends up being queued (because DNS can't be resolved).
    // We'll still see an entry in the downloads UI with a "Queued" label.
    dm.enqueue(new Request(Uri.parse("http://hammychamp.toodles")));
    bots.roots.openRoot("Downloads");
    bots.directory.assertDocumentsPresent("Queued");
}
Also used : Request(android.app.DownloadManager.Request) DownloadManager(android.app.DownloadManager) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 45 with DownloadManager

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

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)

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