Right now I'm currently trying to make a file downloaded from a Uri
, but I wanna make it so that if the file has been downloaded it's wont be able to download it anymore. So i decided to use file.exists()
to do that, But right now the file.exists()
method isn't working for some reason.
Uri uri = Uri.parse("http://kmmc.in/wp-content/uploads/2014/01/lesson2.pdf");
Uri path = Uri.parse("file:///storage/emulated/0/Download/");
String test = uri.getPath();
File file = new File(path.getPath());
File check = new File(path.getPath()+uri.getLastPathSegment());
if (!check.exists()||!check.isFile()) {
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(String.valueOf(file), uri.getLastPathSegment());
Long reference = downloadManager.enqueue(request);
}
Intent intent = new Intent(MainActivity.this,ViewActivity.class);
intent.putExtra("book",""+uri.getLastPathSegment()+"");
startActivity(intent);
I try to do a file check and see if file exist or not, but I always get file doesn't exist even though the file is already downloaded and on the right place. Can someone help me with this?