0

My goal is to list only *.json files in android filebrowser, to load them to the software.

    File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + PATH_TO_WRITE);



    Uri uri = Uri.fromFile(folder);
    intent.setDataAndType(uri, "file/.json");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    Activity activity = (Activity) context;
    activity.startActivityForResult(intent, FILECHOOSER_RESULTCODE);

Looks like the Android filebrowser dosen't support *.json files. Is there way to implement FileFilter to the intent?

user257980
  • 1,059
  • 2
  • 15
  • 31

2 Answers2

2

Have you tried using

intent.setDataAndType(uri, "application/json");

Edit:

It appears although this currently isn't supported in the default android file explorer (Please see this)

  • This dosen't work because android does not support "application/json" – user257980 Dec 17 '19 at 14:25
  • @user257980 It appears that this is correct, this also brings to light another isssue in that on android you can have different file explorers each with their own implementations and intents so there's no guarantee that even if you ask to only show .json files that the file explorer implementation respects your request to do so as suggested [here](https://stackoverflow.com/a/14627787/7535148). I think a better alternative would be to acount for incorrect files being selected and react accordingly – Andrew Rogers Dec 17 '19 at 14:56
0

Sovled this by using custom made file browser because android does not support *.JSON formats. Used this library https://github.com/adityak368/Android-FileBrowser-FilePicker , which was easy to implement

user257980
  • 1,059
  • 2
  • 15
  • 31