0

I am working with an application, where i am uploading files to server like png, pdf, jpeg. When i try to open file manger and open downloads folder then files showing are hidden, i am not able to select these files.

Below is the code :

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/png,image/jpeg,application/pdf,text/plain");
this.startActivityForResult(intent, FILE_SELECT_CODE);

how can i solve this issue so that i can select file from any where from my mobile.

vickyVick
  • 207
  • 3
  • 14
  • Give your multipart request code, and may be there is some issue from server side. – Silvans Solanki Mar 10 '16 at 06:56
  • here is [a link](http://stackoverflow.com/questions/7856959/android-file-chooser)! I think you will find your answer here. – T. Grigoryan Mar 10 '16 at 06:58
  • Why are you looking in the downloads folder after you uploaded files to a server? For what reason? – greenapps Mar 10 '16 at 06:59
  • I don't think so there is any problem with my request, as i am not able to select the image from download folder, as my request is working for selecting files from gallery. – vickyVick Mar 10 '16 at 06:59
  • @greenapps user can upload any file from any where, it can be download folder, or gallery or what. – vickyVick Mar 10 '16 at 07:00
  • So it is before uploading? Its at selection of a file. Still the question is what this has to do with uploading? – greenapps Mar 10 '16 at 07:02
  • Android has no file manager so where are you talking about? What do you mean with files 'showing' are 'hidden'? – greenapps Mar 10 '16 at 07:05
  • @greenapps read the question carefully, it is showing what actually i am asking. I am not able to select the file from download folder prior to upload the file, as it is possible from gallery. – vickyVick Mar 10 '16 at 07:05
  • @greenapps files are there but not able to select them, its just looking as hidden files – vickyVick Mar 10 '16 at 07:06
  • They are all looking like hidden files? But they aren't? How does that look? Android has no file manager as i said before. So which app is in use? And why don't you care to give that info or react on it? – greenapps Mar 10 '16 at 07:09

1 Answers1

1
Intent i = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    Log.e("RegisterACtivity", "OpenGallery");
    startActivityForResult(i, 1);

I am using this code and its working fine for me. but it is opening up the gallery if there will be images in your download folder it will show you definitely.

and below is code to get the result and set that path on your image view. i am setting this first on image view . you can upload your image by converting your path into byte array

protected void onActivityResult(int requestCode, int resultCode,
        Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
    Log.e("RegisterActivity", "" + requestCode + "...." + resultCode);
    switch (requestCode) {
    case 1:
        if (resultCode == RESULT_OK) {
            Uri _image = imageReturnedIntent.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

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

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            imagePath = cursor.getString(columnIndex);
            cursor.close();
            Log.e("FilePath", imagePath);
            image.setImageBitmap(BitmapFactory.decodeFile(imagePath));
            /*
             * Bitmap bitmap = BitmapFactory.decodeFile(imagePath); Bitmap
             * resized = Bitmap.createScaledBitmap(bitmap, 100, 100, true);
             * Bitmap conv_bm = getRoundedRectBitmap(resized, 200);
             * image.setImageBitmap(conv_bm);
             */

        }
    }
}
Jishant
  • 574
  • 3
  • 14