XML : How do I download multiple files from a web service using Download Manager in Android?

I want to download multiple files (one by one) from a web service. Web service output is a XML file. I'm using DocumentBuilderFactory to parse XML. I want to parse the web service output to download manager to download files.

This is what I tried upto now.

   public void startDownload() {     TextView iname[];     TextView itime[];     NodeList nodelist;       String imageName;     String servicestring = Context.DOWNLOAD_SERVICE     downloadmanager = (DownloadManager) getSystemService(servicestring);         Uri uri = Uri.parse("webservice url here");       DownloadManager.Request request = new DownloadManager.Request(uri);            request.setDestinationInExternalPublicDir("/Download","tste.jpg");        downloadId = downloadmanager.enqueue(request);    try {       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();     DocumentBuilder db = dbf.newDocumentBuilder();     Document doc = db.parse("webservice url");       NodeList nodeList = doc.getElementsByTagName("image");      iname = new TextView[nodeList.getLength()];              itime = new TextView[nodeList.getLength()];               Toast.makeText(MainActivity.this, nodeList.getLength(), Toast.LENGTH_SHORT).show();              for (int i = 0; i < nodeList.getLength(); i++) {                    Node node = nodeList.item(i);                  Toast.makeText(MainActivity.this, nodeList.item(i).getNodeValue().toString(), Toast.LENGTH_SHORT).show();                    //vtype[i] = new TextView(this);                  iname[i] = new TextView(this);                  itime[i] = new TextView(this);                    Element fstElmnt = (Element) node;                      NodeList inameList = fstElmnt.getElementsByTagName("iname");                  Element inameElement = (Element) inameList.item(0);                  inameList = inameElement.getChildNodes();                  iname[i].setText(((Node) inameList.item(0)).getNodeValue().trim());                    NodeList itimeList = fstElmnt.getElementsByTagName("itime");                  Element itimeElement = (Element) itimeList.item(0);                  itimeList = itimeElement.getChildNodes();                  itime[i].setText(((Node) itimeList.item(0)).getNodeValue().trim());                    imageName = iname[i].getText().toString().trim();    

No comments:

Post a Comment