2013-02-20 69 views
-1
Cursor appu=X.getsomething(); 

       if (appu.getCount() > 0) 
        { 
        if (appu.moveToFirst()) 
        { 
        do { 
          String uname = appu.getString(appu.getColumnIndex("content_id")); 
          String ax= appu.getString(appu.getColumnIndex("content")); 
          String unknown =url + ax; 
           t1.append("\n"); 
           t1.append(unknown); 
           //downloadimages(unknown,uname); 
         }while (appu.moveToNext()); 
        } 
        X.close(); 

這是我的代碼從數據庫中獲取一些結果,並由此結果我創建一個具有圖像的url,我想爲每個遊標結果下載該圖像,當我嘗試運行downloadimages()函數我的應用程序崩潰總是我不知道爲什麼......但是當我運行代碼沒有它,它運行完美。無法下載圖像?

downloadimages方法

 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 | DownloadManager.Request.NETWORK_MOBILE); 
       request.setAllowedOverRoaming(false); 
      request.setDescription("Android Data download using DownloadManager."); 
      request.setDestinationInExternalFilesDir(getApplicationContext(),Environment.DIRECTORY_DOWNLOADS,v1 + ".jpg"); 
       downloadManager.enqueue(request);  

     } 

,請告訴我,我做錯了什麼???

Cursor appu=X.getsomething(); 

       if (appu.getCount() > 0) 
        { 
        if (appu.moveToFirst()) 
        { 
        do { 
          String uname = appu.getString(appu.getColumnIndex("content_id")); 
          String ax= appu.getString(appu.getColumnIndex("content")); 
          imageid.add(uname); 
          String unknown =url + ax; 
          imagepath.add(unknown); 
          // t1.append("\n"); 
           //t1.append(unknown); 
         }while (appu.moveToNext()); 
        } 
        X.close(); 
        }} 
      this.getitdone(); 
      } 


     public void getitdone() 
     { 
      int b=imagepath.size(); 

      for(int i=1;i<=b;i++) 
      { 
       String extra=imagepath.get(i).toString(); 
       String extra2=imageid.get(i).toString(); 
       downloadimages(extra,extra2); 
      } 

     } 

現在我做這種方式,它是可以正常使用

+0

是否有必要將.JPG文件名添加?下載的MIME類型不應該爲你做什麼?只是猜測,爲什麼你不通過在你的downloadimages函數中放置一個break函數來調試應用程序? – Shouvik 2013-02-20 06:54:36

+0

我已經在文件名中加入了.jpg文件擴展名,請看downloadimages函數 – 2013-02-20 07:22:35

+0

的第二行最後感謝傢伙我已經解決了它自己很抱歉打擾您全部 – 2013-02-20 07:54:21

回答

0

這是普拉莫德如何解決該問題:

Cursor appu=X.getsomething(); 

      if (appu.getCount() > 0) 
       { 
       if (appu.moveToFirst()) 
       { 
       do { 
         String uname = appu.getString(appu.getColumnIndex("content_id")); 
         String ax= appu.getString(appu.getColumnIndex("content")); 
         imageid.add(uname); 
         String unknown =url + ax; 
         imagepath.add(unknown); 
         // t1.append("\n"); 
          //t1.append(unknown); 
        }while (appu.moveToNext()); 
       } 
       X.close(); 
       }} 
     this.getitdone(); 
     } 


    public void getitdone() 
    { 
     int b=imagepath.size(); 

     for(int i=1;i<=b;i++) 
     { 
      String extra=imagepath.get(i).toString(); 
      String extra2=imageid.get(i).toString(); 
      downloadimages(extra,extra2); 
     } 

    } 
+0

嘿謝謝我是新來的stackoverflow,所以我did'nt我不知道我應該發佈它的答案部分 – 2013-02-20 08:49:43

+0

雖然它是真棒的東西得分免費信譽我不這樣做。看看我是如何在這裏做到的。 http://stackoverflow.com/questions/3749880/i-am-able-to-draw-the-box-but-i-am-not-able-to-remove-it-canvas張貼您的答案,以便我可以刪除這一個。 – Shouvik 2013-02-20 09:59:45