i am trying to download images from the web when my app is connected to the internet through this code
public void downloadimages(String url,String filename)
{
String ur1=url,v1=filename;
downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
Uri Download_Uri = Uri.parse(ur1);
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
request.setDescription("Android Data download using DownloadManager.");
request.setDestinationInExternalFilesDir(getApplicationContext(),Environment.DIRECTORY_DOWNLOADS,v1 + ".jpg");
downloadManager.enqueue(request);
}
when i run the app first time downloads happen but the app crashes after that the app did'nt open i am checking for the dowloaded files also:
String path = "/mnt/sdcard/Android/data/com.example.webdata/files/Download/" + extra2 + ".jpg";
tt1.append(path);
File f = new File(path);
if(f.exists())
{
//Toast.makeText(getApplicationContext(), "File already exists....",
// Toast.LENGTH_SHORT).show();
}
else
{
downloadimages(extra,extra2);
}
if the file has been downloaded previously it should not be dowloaded next time ,but i my app crashes and i don't know why any help guys......... this is my logcat output:-
02-21 18:00:41.547: E/AndroidRuntime(23964): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.webdata/com.example.webdata.MainActivity}: java.lang.IndexOutOfBoundsException: Invalid index 1088, size is 1088
Can you show us the code MainActivity
class, because it seems that the error comes from this class.
then the error is a IndexOutOfBoundsException
, so have you tried with less image eg 10 or 20? and run later when the first 10 are recovered?