我知道您可以限制在名为的文件资源管理器中显示的可用文件类型
Intent.ACTION_GET_CONTENT
setType()
,但这只能用于已知的文件扩展名,如.jpg、.pdf、.docx,我需要的是只显示具有
,例如.abc,因此用户只能选择以.abc结尾的文件。我已经搜索了很长时间,仍然找不到有效的方法来解决这个问题;最接近的方法是创建自定义mime类型,如下所示:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:mimeType="application/customtype" />
<data android:pathPattern=".*\\.abc" />
<data android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:mimeType="application/customtype" />
<data android:pathPattern=".*\\.abc" />
<data android:host="*" />
</intent-filter>
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/customtype");
startActivityForResult(intent,FILE_SELECTOR_REQUEST_CODE);