2

Hi I want to browse to a file explorer and select a pdf or image present in some directory. I want the code to do the same.

the below code takes me to gallery and help me choose image but I want to move to file explorer then select file and accordingly I want the code in onactivityResult after selecting.

browsePic.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent i = new Intent(
            Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
        );
        startActivityForResult(i, LOAD_IMAGE_RESULTS);
    }
});
Rudi Kershaw
  • 12,332
  • 7
  • 52
  • 77
  • By coincidence, another user posted a very similar question (`Through my application the user can choose a file from the filemanager and process the choosen file`) some minutes before this post: http://stackoverflow.com/questions/24060059/startactivityforresult-not-working-in-android-version-4-4-kitkat-version He is complaining for KitKat incompatibilities. – Phantômaxx Jun 05 '14 at 12:35
  • Here's a downloadable FileChooser, compatible with API 2.2+, give it a try: https://code.google.com/p/afiledialog/ – Phantômaxx Jun 05 '14 at 13:14
  • Don't forget to upvote any answers that you found helpful, and accept the answer which best answered your question by clicking the grey tick. – Rudi Kershaw Jun 11 '14 at 09:57

2 Answers2

1

I believe you can throw out an open intent for a file chooser using the following.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
try{
    startActivityForResult(intent, LOAD_IMAGE_RESULTS);
} catch (ActivityNotFoundException e){
    Toast.makeText(YourActivity.this, "There are no file explorer clients installed.", Toast.LENGTH_SHORT).show();
}

The trouble is however, this assumes your user has a file browser open to accepting intents installed on their device, when often no such apps are installed on a device by default.

As in the code above, you may have to throw up a dialog if no Activities exist that can accept this intent, explaining that they need to install a file browser. You could even recommend one that you know works with your application.

I hope this helps.

Rudi Kershaw
  • 12,332
  • 7
  • 52
  • 77
  • Any comments on this? http://stackoverflow.com/questions/24060059/startactivityforresult-not-working-in-android-version-4-4-kitkat-version/24060707#24060707 – 2vision2 Jun 05 '14 at 13:21
-1

i think you could do something like this

File strDir = new File("/mnt/"); // where your folder you want to browse inside android

if( strDir.isDirectory()){
     //do something
}
DarkVision
  • 1,373
  • 3
  • 20
  • 33
  • 1
    But he said: `i want to browse to a file explorer and select a pdf or image present in some directory`... how is your code showing a **file explorer**? – Phantômaxx Jun 05 '14 at 12:39
  • Class File has the ability to get list() specific path with that he can get the file he want maybe i am wrong. – DarkVision Jun 05 '14 at 12:42
  • Yes the above code will not take me to file explorer. –  Jun 05 '14 at 12:42
  • like i say you can always change the path inside File constructor you could always passes Environment.getExternalStorageDirectory().getPath() this one is relate to external storage directory – DarkVision Jun 05 '14 at 12:50
  • Help me! It seems like working http://stackoverflow.com/questions/24060059/startactivityforresult-not-working-in-android-version-4-4-kitkat-version/24060707#24060707 can you help me in understanding In the above code can you please explain me what should be R.string.select_file MIME_TYPE_ALL REQUEST_CODE and when to invoke this method. –  Jun 05 '14 at 12:56
  • But then he has to build a dialog with a ListView to list all the files... in other words, he has to build his own file explorer. – Phantômaxx Jun 05 '14 at 13:06