2013-12-08 2 views
1

저는 DownloadManager를 사용하여 파일을 다운로드하고 DownloadManager.COLUMN_LOCAL_URI에서 이름을 가져 왔습니다. 동일한 파일을 11 회 이상 다운로드합니다. 이상한 이름을 이상하게 여기기 시작한 후 11 번. 예 :DownloadManager 이름, 다시 다운로드 한 파일

text.txt

텍스트 1.TXT

텍스트 2.txt

텍스트 3.txt

텍스트 4.txt

텍스트 -5.txt

text-6.txt

텍스트 7.txt

텍스트 8.txt

텍스트 9.txt

텍스트 10.txt

텍스트 26.txt

텍스트 - 14.txt

무엇이 문제 일 수 있습니까?

사전에

편집을 주셔서 감사합니다 :

은 어쩌면 당신은 사용해야 내 코드

public static long downloadFile(Context ctx, String url, String title, String description, String filename, String mimetype, BroadcastReceiver onDownloadComplete) { 
     DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE); 

     Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs(); 
     long res = dm.enqueue(new DownloadManager.Request(Uri.parse(url)).setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI).setAllowedOverRoaming(false).setTitle(title).setMimeType(mimetype).setDescription(description).setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename)); 
     ctx.registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); 
     Toster.showGreenToast(ctx, ctx.getString(R.string.download_started, filename)); 
     return res; 
    } 

    public static String getDownloadCompletedFileName(Context ctx, Intent intent) { 
     String res = ""; 

     try { 
      Bundle extras = intent.getExtras(); 
      DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE); 

      DownloadManager.Query q = new DownloadManager.Query(); 
      q.setFilterById(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID)); 
      Cursor c = dm.query(q); 

      if (c.moveToFirst()) { 
       int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS)); 
       if (status == DownloadManager.STATUS_SUCCESSFUL) { 
        // process download 
        res = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); 
        // get other required data by changing the constant passed to getColumnIndex 
       } 
      } 

      c.close(); 
     } catch (Exception e) {} 

     return res; 
    } 
+0

처음에는 파일 이름을 어떻게 생성하는지 알려주지 않았습니다. –

답변

0

를 가져온다 setDestinationInExternalFilesDir(), setDestinationInExternalPublicDir() 또는 setDestinationUri() 때 파일 이름과 디렉토리를 설정하는 DownloadManager.Request을 만들 수 있습니다. 거기 말한대로

+0

모든 변형을 시도했습니다. 같은 효과 –

관련 문제