19

How to use intent to prompt user to choose "finish action with" to choosing app to select file (assuming there is a few app to browse file in the device)

I want to filter the file using an extension.. (eg. : *.sav, *.props)

Thank you in advance

Tek Yin
  • 3,011
  • 3
  • 25
  • 42
  • visit this thread, http://stackoverflow.com/questions/5537907/view-file-path-in-a-file-manager-as-android-intent If I am not wrong .this might help you. – Ashwin N Bhanushali Mar 29 '12 at 10:50

4 Answers4

46

You can use something like this:

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

But I really doubt that you can set a filter third-party file browsers. Or you can try to use this file dialog: http://code.google.com/p/android-file-dialog/

Gaurav
  • 3,615
  • 2
  • 27
  • 50
Vyacheslav Shylkin
  • 9,741
  • 5
  • 39
  • 34
9

this will open the build-in file explorer if available, otherwise will ask u to select a file explorer that u have installed.

private void showFileChooser() {

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    //intent.setType("*/*");      //all files
    intent.setType("text/xml");   //XML file only
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {
      startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
      // Potentially direct the user to the Market with a Dialog
      Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
    }
}
Gene Bo
  • 11,284
  • 8
  • 90
  • 137
Renato Martins
  • 258
  • 2
  • 7
3

It may help you to choose a doc file and u may change action as per your need

        Intent intent;
        if (VERSION.SDK_INT >= 19) {
            intent = new Intent("android.intent.action.OPEN_DOCUMENT");
            intent.setType("*/*");
        } else {
            PackageManager packageManager =getActivity().getPackageManager();
            intent = new Intent("android.intent.action.GET_CONTENT");
            intent.setType("file*//*");
            if (packageManager.queryIntentActivities(intent,MEDIA_TYPE_IMAGE).size() == 0) {
                UserToast.show(getActivity(), getResources().getString(R.string.no_file_manager_present));
            }
        }
        if (getActivity().getPackageManager().resolveActivity(intent, NativeProtocol.MESSAGE_GET_ACCESS_TOKEN_REQUEST) != null) {
            startActivityForResult(intent, UPLOAD_FILE);
        }
Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
Nilesh
  • 1,013
  • 14
  • 21
-10
// check here to KitKat or new version and this will solve the Samsung file explore issue too.  
boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

if (isKitKat) {
    Intent intent = new Intent(); 
    intent.setType("*/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(intent,FILE_SELECT_CODE);
} else {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    startActivityForResult(intent,FILE_SELECT_CODE);
}
Vukašin Manojlović
  • 3,717
  • 3
  • 19
  • 31
Dinesh IT
  • 87
  • 2