Skip to content

Instantly share code, notes, and snippets.

@milon87
Last active March 22, 2017 05:41
Show Gist options
  • Save milon87/72c354984ae52727e90b4297b553b17b to your computer and use it in GitHub Desktop.
Save milon87/72c354984ae52727e90b4297b553b17b to your computer and use it in GitHub Desktop.
Download file android
class FileDownloader{
public static void image_download(Context context, String uRl, String bookNmae) {
File direct = new File(Environment.getExternalStorageDirectory()
+ "/appFolderName/images");
String imageName = uRl.substring(uRl.lastIndexOf('/') + 1, uRl.length());
if (!direct.exists()) {
direct.mkdirs();
}
DownloadManager mgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(uRl);
DownloadManager.Request request = new DownloadManager.Request(
downloadUri);
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN)
.setAllowedOverRoaming(false).setTitle("thumbnail")
.setDestinationInExternalPublicDir("/eBoiMela/images", bookNmae + ".jpg");
mgr.enqueue(request);
}
// File folder = new File(Environment.getExternalStorageDirectory(), "/folderName");
public static void searchFolderRecursiveForPDF(File folder) {
if (folder != null) {
if (folder.listFiles() != null) {
for (File file : folder.listFiles()) {
if (file.isFile()) {
//.pdf files
if ((file.getName().contains(".pdf")) || file.getName().contains(".PDF")) {
// Log.e("ooooooooooooo", "path__="+file.getName());
file.getPath();
//two list to hold name and path
pdf_file_name.add(file.getName());
pdf_file_path.add(file.getPath());
StaticVariable.file_path.add(file);
// Log.e("pdf_paths", "" + pdf_names);
}
} else {
searchFolderRecursiveForPDF(file);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment