0

I want to make a button to be able to display selected document names from the downloads folder that can be found in the "My Files" app in android, but i cant seem to find the right path to get to the documents. Anyone knows the path? I have tried ways like

Environment.getExternalStorageState()

but im not getting the downloads folder, instead it goes to google drive to select. this is how im using the 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;

also a problem with editing the textviews im using, i cant seem to delete the text using the spannable class. any help with that will be good

my codes for the spannable class

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;
}
Wei Xiong
  • 167
  • 4
  • 13

2 Answers2

0

This answer might have answered already what you need: https://stackoverflow.com/a/7908446/8050896

Did you try to write the Environment.DIRECTORY_DOWNLOADS constant?

Make sure you have the proper permissions in the manifest set as well.

P Fuster
  • 2,224
  • 1
  • 20
  • 30
  • already went to that link prior to asking, brings me to google drive and not the downloads folder. may i know if is the right permission? – Wei Xiong Sep 22 '17 at 08:45
  • Yes that would be right, could also be the WRITE permission if you plan on doing so. – P Fuster Sep 22 '17 at 08:53
  • Just to double check you tried Environment.getExternalStoragePublicDirectory() instead of getExternalStorageState() right ? – P Fuster Sep 22 '17 at 08:55
  • Yes i have tried that too, all lead to google drive, no im not planning to edit anything thats inside, only retrieving – Wei Xiong Sep 22 '17 at 08:56
  • Another method that could work could be to use Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/" . – P Fuster Sep 22 '17 at 08:57
  • not sure if that works, brings me to gallery, but im not sure if MediaStore.Images.Media.EXTERNAL_CONTENT_URI in the intent is the cause... im quite new to this so pardon my uncertainty :) – Wei Xiong Sep 22 '17 at 09:04
  • I'm not great myself! It might be because of the URI pointing to the images gallery. Can you Log what you get when you write `Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()` ? That could help us see where it is directing you. – P Fuster Sep 22 '17 at 09:21
  • content://media/external/images/media it leads me to this, i think its due to the intent – Wei Xiong Sep 22 '17 at 09:40
  • Ok, you should post more of the code then to show how you are using the Uri. – P Fuster Sep 22 '17 at 10:09
  • Okkay... well im off work now ill probably get back here in 3 days – Wei Xiong Sep 22 '17 at 10:10
  • So in the code you are finding the absolute path of the image in the MediaStore. That should not have to do with anything on Environment.getExternalStoragePublicDirectory(Environment.DI‌​RECTORY_DOWNLOADS). I can't think of anything other than your default directory is set to the drive cloud. – P Fuster Sep 25 '17 at 22:48
0

Well... got my answer while trying to find how to upload PDF to server... Here's where i got the answer to go to downloads folder, im still trying to find out how to display the name

Wei Xiong
  • 167
  • 4
  • 13