Skip to content

Instantly share code, notes, and snippets.

@t-kashima
Created October 16, 2015 06:35
Show Gist options
  • Save t-kashima/4a5e5a0bf1105e232a92 to your computer and use it in GitHub Desktop.
Save t-kashima/4a5e5a0bf1105e232a92 to your computer and use it in GitHub Desktop.
DownloadManagerで画像をダウンロードしてDownloadディレクトリに保存する
DownloadManager downLoadManager = (DownloadManager)getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(imageUri);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "image.png");
File pathExternalPublicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
pathExternalPublicDir.mkdirs();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.allowScanningByMediaScanner();
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
downLoadManager.enqueue(request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment