WebサービスからAndroidアプリ(Webサービスの出力 - XML)にアイテムをダウンロードしたい。 Androidダウンロードマネージャーを使ってダウンロードしています。Webサービスから最初のアイテムのみをダウンロードする - Android
ダウンロードボタンをクリックすると、XMLリストの最初の項目のみがダウンロードされます。これが私が試みたものです。すべてのファイルをダウンロードしてください。
try {
URL url = new URL("http://localhost/WebService/gettext.aspx? ");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("image");
iname = new TextView[nodeList.getLength()];
itime = new TextView[nodeList.getLength()];
int listlength = nodeList.getLength();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
itime[i] = new TextView(this);
iname[i] = new TextView(this);
Element fstElmnt = (Element) node;
NodeList nameList = fstElmnt.getElementsByTagName("iname");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
iname[i].setText(((Node) nameList.item(0)).getNodeValue());
NodeList itimeList = fstElmnt.getElementsByTagName("itime");
Element websiteElement = (Element) itimeList.item(0);
itimeList = websiteElement.getChildNodes();
itime[i].setText("ITime = "
+ ((Node) itimeList.item(0)).getNodeValue());
imgName=iname[i].getText().toString().trim();
//Image folder.
dwnload_file_path = "http://localhost/WebService/Images/"+URLEncoder.encode(iname[i].getText().toString(),"UTF-8");
String servicestring = Context.DOWNLOAD_SERVICE;
downloadmanager = (DownloadManager) getSystemService(servicestring);
Uri uri = Uri.parse(dwnload_file_path);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDestinationInExternalPublicDir("/Download",imgName.toString());
downloadId = downloadmanager.enqueue(request);
}
} catch (Exception e) {
System.out.println("EEEEEEEEE "+ e.toString());
//Toast.makeText(getBaseContext(),"35",Toast.LENGTH_SHORT).show();
}
これはWebサービスからのXML出力です。
<!-- language: xml -->
<image>
<iname>abdf.jpg</iname>
<itime>10000</itime>
<iname>bcdf.jpg</iname>
<itime>10000</itime>
<iname>cd.jpg</iname>
<itime>10000</itime>
<iname>efe.jpg</iname>
<itime>10000</itime>
<iname>ggef.jpg</iname>
<itime>10000</itime>
<iname>hiefef.jpg</iname>
<itime>10000</itime>
<iname>mmfer.jpg</iname>
<itime>10000</itime>
<iname>nnnef.jpg</iname>
<itime>10000</itime>
<iname>erer.jpg</iname>
<itime>10000</itime>
</image>
は私に0を交換してみてください、それはDeepanshuHarbola- @ nameList.item(I) –
をワーク・も答えてくれてありがとう。私は試した。しかし、同じ結果。最初のアイテムをダウンロードするだけです。 – hiranya