2017-09-22 13 views
0

我想製作一個按鈕,以便能夠顯示從Android的「我的文件」應用程序中可以找到的下載文件夾中選定的文檔名稱,但是我似乎找不到找到文件的正確途徑。任何人都知道路徑?我曾嘗試類似的方式按下按鈕從下載文件夾中選擇文檔以顯示其名稱

Environment.getExternalStorageState() 

,但我不是得到下載文件夾中,而不是將其轉到Google雲端硬盤選擇。 這是即時通訊使用uri。

else if (btnNo == 5) { 
      // File downloads = new File(String.valueOf(Environment.getExternalStorageState())); 
       //create new file directory object 
       //File downloads = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()); 
       Uri selectedImage = data.getData(); 
       String[] filePathColumn = {MediaStore.Images.Media.DATA}; 

       Cursor cursor = getContentResolver().query(selectedImage, 
         filePathColumn, null, null, null); 
       cursor.moveToFirst(); 

       int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
       String picturePath = cursor.getString(columnIndex); 
       cursor.close(); 
       File f = new File(picturePath); 
       tvOther = (TextView) findViewById(R.id.textViewOtherImage); 
       tvOther2 = (TextView) findViewById(R.id.textViewOtherImage2); 
       tvOther3 = (TextView) findViewById(R.id.textViewOtherImage3); 
       tvOther4 = (TextView) findViewById(R.id.textViewOtherImage4); 
       tvOther5 = (TextView) findViewById(R.id.textViewOtherImage5); 
       tvOther6 = (TextView) findViewById(R.id.textViewOtherImage6); 
       tvOther7 = (TextView) findViewById(R.id.textViewOtherImage7); 
       tvOther8 = (TextView) findViewById(R.id.textViewOtherImage8); 
       tvOther9 = (TextView) findViewById(R.id.textViewOtherImage9); 
       tvOther10 = (TextView) findViewById(R.id.textViewOtherImage10); 
       if (tvOther.getText() == "") { 
        tvOther.setText(addClickablePart("[" + f.getName() + "]"), TextView.BufferType.EDITABLE); 
        iv_3 = BMP.getBytes(BitmapFactory.decodeFile(picturePath)); 
        to_attach_img_name_3 = f.getName(); 
        imgArr[2] = to_attach_img_name_3; 

還有一個編輯textviews即時通訊使用的問題,我似乎不能刪除使用spannable類的文本。與任何幫助將是很好的

我對spannable類代碼

private SpannableStringBuilder addClickablePart2(String str) { 
    SpannableStringBuilder ssb = new SpannableStringBuilder(str); 

    int idx1 = str.indexOf("["); 
    int idx2 = 0; 
    while (idx1 != -1) { 
     idx2 = str.indexOf("]", idx1) + 1; 

     final String clickString = str.substring(idx1, idx2); 
     ssb.setSpan(new ClickableSpan() { 

      @Override 
      public void onClick(View widget) { 
       tvOther2.setText(""); 
      } 
     }, idx1, idx2, 0); 
     idx1 = str.indexOf("[", idx2); 
    } 

    return ssb; 
} 

回答

0

這個答案可能已經回答了你所需要的:https://stackoverflow.com/a/7908446/8050896

你嘗試寫Environment.DIRECTORY_DOWNLOADS不變?

確保您在清單集中也有適當的權限。

+0

在詢問之前已經進入該鏈接,將我帶到谷歌驅動器,而不是下載文件夾。我可以知道如果<使用權限的android:name =「android.permission.READ_EXTERNAL_STORAGE」/>是正確的權限? –

+0

是的,如果你打算這麼做的話,那也可能是寫權限。 –

+0

只是爲了仔細檢查你嘗試Environment.getExternalStoragePublicDirectory()而不是getExternalStorageState()正確嗎? –

0

嗯...有我的答案,而試圖... Here's在那裏我得到了答案去下載文件夾,我還在試圖找出如何顯示名稱查找如何上傳PDF到服務器