badboy1245
Newbie
I'm using download manager to download a txt file to my folder but it wont download on my virtual machine and also it wont work on a samsug phone but it works on my nexus phone. here is by code and I put the promissions in the menifest.xml, can you tell my why it wont download on my virtual machine, here is my code
Code:
downloadlist.setOnClickListener(new View.OnClickListener() {
[USER=1021285]@override[/USER]
public void onClick(View v) {
//for downloading the TR.pls into
String downloadlocation = "/Downloadstationlist";
// File folder1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Downloadstationlist/RT.pls");
String[] mPermission = {Manifest.permission.READ_CONTACTS, Manifest.permission.READ_SMS,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
try {
File folder1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Downloadstationlist/RT.pls");
if (folder1.exists()) {
folder1.delete();
//file2.delete();
}
// File f = new File(Environment.getExternalStorageDirectory() + downloadlocation); // location, where to download file in external directory
// if (!f.exists()) {
// f.mkdirs();
// }
// deleteFile("/storage/emulated/0/Download/RT.pls");
DownloadManager.Request request = new DownloadManager.Request(Uri.parse("https://old.friezy.ru/pls/RT.pls"));
Toast.makeText(MainActivity.this, "Downloading Your Station List...", Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this, "RESTART YOUR APP", Toast.LENGTH_LONG).show();
// request.setTitle("Downloading Your Station List..."); //set title for notification in status_bar
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //flag for if you want to show notification in status or not
//String nameOfFile = "YourFileName.pdf"; //if you want to give file_name manually
String nameOfFile = URLUtil.guessFileName("https://old.friezy.ru/pls/RT.pls", null, MimeTypeMap.getFileExtensionFromUrl("https://api.friezy.ru/playlists/pls/RT.pls")); //fetching name of file and type from server
request.setDestinationInExternalPublicDir(downloadlocation, nameOfFile);
DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.enqueue(request);
} catch (Exception e) {
// handle exception
}
}
});
Last edited by a moderator: