Download files from url in aide ide project
Tutorial on how to download files from url in your aide ide project.
first add permission in your AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Next goto your java class and add this permission, this permission is very important on higher version of android.
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
Log.e("Permission error","You have permission");
}else{
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
}
Last step is download code:
DownloadManager.Request request = new DownloadManager.Request(Uri.parse("https://yourfiles.com/example.pdf"));
request.setTitle("Name of File");
request.setDescription("Download modded games version");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
String filename = URLUtil.guessFileName(fleName, null, MimeTypeMap.getFileExtensionFromUrl(fleLnk));
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
Comments
Post a Comment
Leave a comment hdh