Upload files from phone intent

2.7k views Asked by At

I've an android application where in an activity the user chooses a picture from the phone's memory to upload it to the server using the Action Pick intent

Intent i = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, RESULT_LOAD_IMAGE);

However; now the requirements has changed and the client wants to upload any file with any extension, what intent should I use in order to open the phone's memory (like the file manager) and choose whatever I want?

Now I'm using the Get content intent thanks to you guys:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    startActivityForResult(intent, 1);

but the problem is in the start activity for result

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == 1) {
            Log.d("select pivture", "passed her");
            Uri selectedMediaUri = data.getData();

            String Fpath = selectedMediaUri.getPath();

            Log.d("Fpath", Fpath);
}

I get as follows:

/document/primary:Download/tool208.pdf

Which is not what I want, I want path like this one:

/external/images/media/6634
1

There are 1 answers

4
Noorul On BEST ANSWER

Use below method:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

UPDATE

   @Override  
   protected void onActivityResult(int requestCode, int resultCode, Intent data)  
   {  
          super.onActivityResult(requestCode, resultCode, data);  
         if(requestCode==PICKFILE_REQUEST_CODE){  
         }  
 }