使用意图搜索json文件

use*_*059 7 android json android-intent

json 文件(json 扩展名)的正确 MIME 类型是什么,以便在我通过意图浏览文件系统时只看到 json 文件?

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

谢谢

Sta*_*tan 6

令人惊讶的是,Android 不支持“json”(对于 javascript 扩展名为“js”)作为 MIME 类型。例如,从MimeUtils的源代码中可以清楚地看出这一点。您也可以使用MimeTypeMap辅助类并找出:

MimeTypeMap.getSingleton().getMimeTypeFromExtension("json");
Run Code Online (Sandbox Code Playgroud)

返回null

唯一可以用来代替“application/json”的最接近的 MIME 类型是“application/octet-stream”:它匹配“*.json”文件以及其他很多东西。至少它过滤掉了图像、文本、音乐文件和视频。