Search code examples
androidintentfilter

How to write an Intent to display file with only desired extensions in Android


I am developing an android app that encrypts/decrypts file.

Once a file is encrypted, its extension changes to filename.encrypted ( here filename is itself a fully qualified filename like hello.pdf, so the encrypted file becomes hello.pdf.encypted).

I have intregrated a file chooser intent in my app, so that user don't need to open a third party intent to choose the files.

My problem is, while user selects to Encrypt a file, he should not be allowed to choose files that are already encrypted i.e. having the extension ".encrypted" and when they are trying to Decrypt a file they should only see the files with the extension ".encrypted".

I have seen a lot of file chooser intents like (https://github.com/iPaulPro/aFileChooser) and (http://code.google.com/p/android-filechooser/) but none have the ability to customize the viewable/selectable files. I read a post (Android file chooser) that says, it cannot be done, but I have seen apps that have implemented this feature.

I am need of help in some resources or links that shows me how is that possible to achieve. I strongly believe the functionality is possible.

Besides, I would also like my app to recognize the extension ".encrypted" when viewed from a third party file manager. I believe that is possible by indicating it in the Android Manifest, but I failed to make it possible. I read this post: Register new file type in Android but could not do it.

Looking for some help here.


Solution

  • I found a library https://github.com/Kaloer/Android-File-Picker-Activity for the thing I wanted to achieve.

    They have given us provision to specify allowed extensions using putExtra in the intent.

    May be it would be useful to others with similar problems.