use of android.app.DownloadManager in project android_frameworks_base by ResurrectionRemix.
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();
}
use of android.app.DownloadManager in project Tusky by Vavassor.
the class ViewMediaFragment method downloadImage.
private void downloadImage() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && ContextCompat.checkSelfPermission(this.getContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
android.support.v4.app.ActivityCompat.requestPermissions(getActivity(), new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
} else {
//download stuff
String url = getArguments().getString("url");
Uri uri = Uri.parse(url);
String filename = new File(url).getName();
DownloadManager downloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.allowScanningByMediaScanner();
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, getString(R.string.app_name) + "/" + filename);
downloadManager.enqueue(request);
}
}
use of android.app.DownloadManager in project apps-android-commons by commons-app.
the class MediaDetailPagerFragment method downloadMedia.
/**
* Start the media file downloading to the local SD card/storage.
* The file can then be opened in Gallery or other apps.
*
* @param m Media file to download
*/
private void downloadMedia(Media m) {
String imageUrl = m.getImageUrl(), fileName = m.getFilename();
// Strip 'File:' from beginning of filename, we really shouldn't store it
fileName = fileName.replaceFirst("^File:", "");
Uri imageUri = Uri.parse(imageUrl);
DownloadManager.Request req = new DownloadManager.Request(imageUri);
//These are not the image title and description fields, they are download descs for notifications
req.setDescription(getString(R.string.app_name));
req.setTitle(m.getDisplayTitle());
req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
// Modern Android updates the gallery automatically. Yay!
req.allowScanningByMediaScanner();
req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !(ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
Snackbar.make(getView(), R.string.storage_permission_rationale, Snackbar.LENGTH_INDEFINITE).setAction(R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 1);
}
}).show();
} else {
final DownloadManager manager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(req);
}
}
Aggregations