2016-03-04 107 views
1

我正在使用afilechooser爲此目的。這是默認編程來選擇文件夾內的項目,並獲得用戶選擇的路徑。文件選擇器選擇文件夾(安卓)

但我想用它作爲文件夾選擇器,用戶從Android設備的內存中選擇一個位置,然後應用程序將該文件保存在該位置。

那麼我該怎麼做。

我使用用於此目的的代碼是 -

private void showChooser() { 
    // Use the GET_CONTENT intent from the utility class 
    Intent target = FileUtils.createGetContentIntent(); 
    // Create the chooser Intent 
    Intent intent = Intent.createChooser(
      target, getString(R.string.chooser_title)); 
    try { 
     startActivityForResult(intent, REQUEST_CODE); 
    } catch (ActivityNotFoundException e) { 
     // The reason for the existence of aFileChooser 
    } 
} 

,我懷疑的代碼可以改爲選擇文件夾而不是文件。任何建議都可能有所幫助。請提出建議,如果有任何其他方式來實現想要的。

謝謝

回答

0

在您發佈的URL GitHub的項目看,它看起來並不像可以做到這一點。我的主張是基於內部com.ipaulpro.afilechooser.FileChooserActivity類下面的代碼:

@Override 
public void onFileSelected(File file) { 
    if (file != null) { 
     if (file.isDirectory()) { 
      replaceFragment(file); 
     } else { 
      finishWithResult(file); 
     } 
    } else { 
     Toast.makeText(FileChooserActivity.this, R.string.error_selecting_file, 
       Toast.LENGTH_SHORT).show(); 
    } 
} 

只看if(file.isDirectory())聲明。

+0

你能否爲此提出其他建議? –

+0

不,我不知道任何替代品,但是因爲您已經在工作區中擁有代碼,所以您可以嘗試使其適應您的需要。 – pleft

+0

我想選擇文件夾來選擇保存文件的路徑。但是這是選擇文件夾中的項目。無論如何,我會繼續努力。 –