use of android.app.DownloadManager.Request in project XposedInstaller by rovo89.
the class DownloadsUtil method add.
private static DownloadInfo add(Builder b) {
Context context = b.mContext;
removeAllForUrl(context, b.mUrl);
if (!b.mDialog) {
synchronized (mCallbacks) {
mCallbacks.put(b.mUrl, b.mCallback);
}
}
Request request = new Request(Uri.parse(b.mUrl));
request.setTitle(b.mTitle);
request.setMimeType(b.mMimeType.toString());
if (b.mDestination != null) {
b.mDestination.getParentFile().mkdirs();
removeAllForLocalFile(context, b.mDestination);
request.setDestinationUri(Uri.fromFile(b.mDestination));
}
request.setNotificationVisibility(Request.VISIBILITY_VISIBLE);
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
long id = dm.enqueue(request);
if (b.mDialog) {
showDownloadDialog(b, id);
}
return getById(context, id);
}
use of android.app.DownloadManager.Request in project robolectric by robolectric.
the class ShadowDownloadManagerTest method query_shouldReturnAll.
@Test
public void query_shouldReturnAll() {
ShadowDownloadManager manager = new ShadowDownloadManager();
manager.enqueue(request.setDestinationUri(destination));
Uri secondUri = Uri.parse("http://example.com/foo2.mp4");
Uri secondDestination = Uri.parse("file:///storage/foo2.mp4");
Request secondRequest = new Request(secondUri);
manager.enqueue(secondRequest.setDestinationUri(secondDestination));
Cursor cursor = manager.query(new DownloadManager.Query());
cursor.moveToNext();
assertThat(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_URI))).isEqualTo(uri.toString());
assertThat(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))).isEqualTo(destination.toString());
cursor.moveToNext();
assertThat(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_URI))).isEqualTo(secondUri.toString());
assertThat(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))).isEqualTo(secondDestination.toString());
}
use of android.app.DownloadManager.Request 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);
}
use of android.app.DownloadManager.Request in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerStressTest method testMultipleDownloads.
/**
* Attempts to download several files simultaneously
*/
@LargeTest
public void testMultipleDownloads() throws Exception {
// need to be sure all current downloads have stopped first
removeAllCurrentDownloads();
int NUM_FILES = 10;
// 10 kb
int MAX_FILE_SIZE = 10 * 1024;
Random r = new LoggingRng();
for (int i = 0; i < NUM_FILES; ++i) {
int size = r.nextInt(MAX_FILE_SIZE);
byte[] blobData = generateData(size, DataType.TEXT);
Uri uri = getServerUri(DEFAULT_FILENAME + i);
Request request = new Request(uri);
request.setTitle(String.format("%s--%d", DEFAULT_FILENAME + i, i));
// Prepare the mock server with a standard response
enqueueResponse(buildResponse(HTTP_OK, blobData));
long requestID = mDownloadManager.enqueue(request);
}
waitForDownloadsOrTimeout(WAIT_FOR_DOWNLOAD_POLL_TIME, MAX_WAIT_FOR_DOWNLOAD_TIME);
Cursor cursor = mDownloadManager.query(new Query());
try {
assertEquals(NUM_FILES, cursor.getCount());
if (cursor.moveToFirst()) {
do {
int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
String filename = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_URI));
String errorString = String.format("File %s failed to download successfully. Status code: %d", filename, status);
assertEquals(errorString, DownloadManager.STATUS_SUCCESSFUL, status);
} while (cursor.moveToNext());
}
assertEquals(NUM_FILES, mReceiver.numDownloadsCompleted());
} finally {
cursor.close();
}
}
use of android.app.DownloadManager.Request in project android_frameworks_base by ParanoidAndroid.
the class DownloadManagerFunctionalTest method doErrorTest.
/**
* Verifies a particular error code was received from a download
*
* @param uri The uri to enqueue to the DownloadManager
* @param error The error code expected
* @throws Exception if the test fails
*/
public void doErrorTest(Uri uri, int error) throws Exception {
Request request = new Request(uri);
request.setTitle(DEFAULT_FILENAME);
long dlRequest = mDownloadManager.enqueue(request);
waitForDownloadOrTimeout(dlRequest);
Cursor cursor = getCursor(dlRequest);
try {
verifyInt(cursor, DownloadManager.COLUMN_REASON, error);
} finally {
cursor.close();
}
}
Aggregations