Download files from url in aide ide project

aide ide tutorials

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

Popular posts from this blog

Implement in-app purchase in aide ide

Implement google admob interstitial ads in aide ide

Implement a-ads on blogger or website

Android play .gif file on imageview in aide ide

Aide ide tutorial - Add line graph


Malitanyo Developer blog & tutorial 2020
Refund Policy    Facebook Page    Google Play

Blogger.com