Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

search json file using intent

What is the correct MIME type for json file(json extnesion) so that only see json files show up when I am browsing the file system through intent?

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("application/json");
    Intent i = Intent.createChooser(intent, "View Default File Manager");
    startActivityForResult(i, 1);

thanks

like image 963
user4182059 Avatar asked Nov 23 '14 17:11

user4182059


1 Answers

Surprisingly, Android does NOT support "json" (and "js" for javascript extension) as a MIME type. This is clear, for example, from the source codes of MimeUtils. Also you can use MimeTypeMap helper class and find out that:

MimeTypeMap.getSingleton().getMimeTypeFromExtension("json");

returns null;

The only most close MIME type that can be used instead of "application/json" is "application/octet-stream": it matches "*.json" files among other things, but a lot of other stuff as well. At least it filters out images, texts, music files and videos.

like image 121
Stan Avatar answered Oct 26 '22 17:10

Stan