Integrate Android File Picker : PhotoPicker and Document Picker on Android

Hey guys! Today I am going to tell you about this module that I created a few days ago through which a user can easily click or select a photo and select different types of documents. Actually, I was working on a android project that requires uploading multiple attachments which can be an image or a document. I searched on github if there was any library that can do this both task but there are nothing according to the requirements. So, I decided to built myself .

View Project on Github

Through this library, you can select multiple photos, click new images, select multiple documents ( PPTs, PDFs, DOCs, EXCELs,TXTs).

Supported Document extensions: .pdf, .ppt, .pptx, .doc, .docx, .xls, .xlsx, .txt

Installation:

  • As of now, It is only available in jCenter(), So just put this in your app dependencies:
    compile 'com.droidninja:filepicker:1.0.0'
  • If you are using Application class in the manifest file (android:name), you need to include tools:replace=”android:name” in the tag. e.g
    <application
            android:name=".ApplicationClass"
            android:icon="@drawable/ic_launcher"
            tools:replace="android:name">
            ......
            </application>
    

Integration:

  1. In your activity, where you want to open this picker on button click just add this code:
    For PhotoPicker:
    FilePickerBuilder.getInstance().setMaxCount(5)
     .setSelectedFiles(filePaths)
     .setActivityTheme(R.style.AppTheme)
     .pickPhoto(this);
    

    For Document Picker:

    FilePickerBuilder.getInstance().setMaxCount(10)
     .setSelectedFiles(filePaths)
     .setActivityTheme(R.style.AppTheme)
     .pickDocument(this);
    

    Here,
    setMaxCount(int count) : set maximum number of selection
    setSelectedFiles(List<String> filepaths): If you have already selected some files, put those in here.
    setActivityTheme(int style): Every app has unique design, unique theme. So just customise your theme for filepicker. This library uses DarkActionBar theme for activity, make a custom filepicker theme and set this method. e.g.

    
    
    <style name="FilePickerTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>
    
    
    

    Note that this custom has parent Theme.AppCompat.Light.DarkActionBar.

  2. After this, select photo or document. Click on Done and you will get your results in onActivityResult() method.
    @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          switch (requestCode)
          {
              case FilePickerConst.REQUEST_CODE:
                  if(resultCode==RESULT_OK && data!=null)
                  {
                      filePaths = data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_PHOTOS);
                      //use them anywhere
                  }
          }
      }
    

Check out this library, file a bug on github if there’s a problem.

  • Elpoulpator

    Hi,
    can we use your File Picker for “PhotoPicker” AND “Document Picker” together, with a unique maxcount ?

    Best regards from French Alps 😉

    Emmanuel

    • Yash Jain

      Hi,

      I also need it in the same way. Are u able to do the same ?

      Regards,
      Yash Jain