Java Code Examples for com.android.storagemanager.deletionhelper.FetchDownloadsLoader

Following code examples demonstrate how to use com.android.storagemanager.deletionhelper.FetchDownloadsLoaderfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.android.storagemanager.deletionhelper.FetchDownloadsLoaderand various code implementation of this class.

    public Loader<DownloadsResult> onCreateLoader(int id, Bundle args) {
        return new FetchDownloadsLoader(mContext,
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
    } 


    public void testNewFilesDontCount() throws Exception {
        temporaryFolder.newFile();
        makeClearableFile();

        DownloadsResult result =
                FetchDownloadsLoader.collectFiles(temporaryFolder.getRoot());
        assertNotNull(result);
        assertEquals(0, result.totalSize);
        assertEquals(1, result.files.size());
    } 

    public void testFilesInDirectory() throws Exception {
        makeClearableFile();
        makeClearableFile();

        DownloadsResult result =
                FetchDownloadsLoader.collectFiles(temporaryFolder.getRoot());
        assertNotNull(result);
        assertEquals(0, result.totalSize);
        assertEquals(2, result.files.size());
    } 

    public void testNestedDirectories() throws Exception {
        File tempDir = temporaryFolder.newFolder();

        File testFile = File.createTempFile("test", null, tempDir);
        testFile.setLastModified(0);
        testFile.deleteOnExit();
        DownloadsResult result =
                FetchDownloadsLoader.collectFiles(temporaryFolder.getRoot());
        assertNotNull(result);
        assertEquals(0, result.totalSize);
        assertEquals(1, result.files.size());
    } 

    public void testEmptyDirectory() throws Exception {
        DownloadsResult result =
                FetchDownloadsLoader.collectFiles(temporaryFolder.getRoot());
        assertNotNull(result);
        assertEquals(0, result.totalSize);
        assertEquals(0, result.files.size());
    } 

    public void testSumFileSizes() throws Exception {
        File first = temporaryFolder.newFile();
        FileWriter fileWriter = new FileWriter(first);
        fileWriter.write("test");
        fileWriter.close();
        first.setLastModified(0);

        File second = temporaryFolder.newFile();
        fileWriter = new FileWriter(second);
        fileWriter.write("test2");
        fileWriter.close();
        second.setLastModified(0);

        DownloadsResult result =
                FetchDownloadsLoader.collectFiles(temporaryFolder.getRoot());
        assertNotNull(result);
        assertEquals(9, result.totalSize);
        assertEquals(2, result.files.size());
    } 

Advertisement
Javadoc
FetchDownloadsLoader is an asynchronous task which returns files in the Downloads directory which ha

ve not been modified in longer than 90 days.

Read More
Advertisement