Monday, November 25, 2013

File object can't find the file when there is one [android help]


File object can't find the file when there is one



In my app After user clicks on a button ,the download manager starts to download a file from internet and saving it to the internal sd card using this code:



void startDownload()
{
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs();
download_req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle(PersianReshape.reshape("Downloading"))
.setDescription(PersianReshape.reshape("currently downloading the file..."))
.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().getAbsolutePath() , packageId + ".sqlite");
download_ID = mgr.enqueue(download_req);
}


After it is downloaded, I plan to check its existance everytime app runs with this code:



String DatabaseAddress =
Environment.getExternalStorageDirectory().getAbsolutePath() +
"/ee.sqlite";
File file = new File(DatabaseAddress);
Log.d("PATH File: ", DatabaseAddress);
if (file.exists()){
Toast.makeText(getApplicationContext(), "found", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "not found", Toast.LENGTH_SHORT).show();
}


Now when I run this code it returns "not found" message whereas the file is already there (I checked its existance using a file manager).


the device I test on is nexus 7 and path used in saving the download file is: /storage/emulated/0/ee.sqlite


ee.sqlite is the filename of downloaded file.


/storage/emulated/0/ is the default path returned by app


Permissions added to manifest for this code are:







Q: Why does file.exists() returns false when there is a file?



Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...