无法下载图片?

时间:2013-02-20 06:50:05

标签: android cursor android-download-manager

  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);
            }

        }

现在我正在这样做,它运作得很好

1 个答案:

答案 0 :(得分:0)

这就是Pramod如何解决这个问题:

 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);
        }

    }