意图ACTION_OPEN_DOCUMENT不填充RTF

时间:2016-09-15 08:26:53

标签: android android-intent

我正在设置文件选择器意图,但它不会过滤RFT文件。

private void openFilePicker(){
    Intent fileIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    fileIntent.addCategory(Intent.CATEGORY_OPENABLE);
    fileIntent.setType("*/*");
    String[] mimetypes = {"text/plain", "text/html", "text/richtext", "application/rtf", "application/x-rtf"};

    fileIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);

    String title = getResources().getString(R.string.chooser_title);

    Intent chooser = Intent.createChooser(fileIntent, title);

    if(fileIntent.resolveActivity(getPackageManager()) != null){
        startActivityForResult(chooser, GET_FILE_CODE);
    }else{
        //display error message here
    }
}

此代码过滤txt和html文件,但不过滤rtf。

enter image description here

我从这里获得了mime类型:https://www.sitepoint.com/web-foundations/mime-types-complete-list/

1 个答案:

答案 0 :(得分:0)

缺少mime类型列表text/rtf,包括这样可以过滤rtf文件。